001
014
015 package com.liferay.portlet.asset.service.persistence;
016
017 import com.liferay.portal.kernel.bean.BeanReference;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
020 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
022 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
023 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
024 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
026 import com.liferay.portal.kernel.dao.orm.FinderPath;
027 import com.liferay.portal.kernel.dao.orm.Query;
028 import com.liferay.portal.kernel.dao.orm.QueryPos;
029 import com.liferay.portal.kernel.dao.orm.QueryUtil;
030 import com.liferay.portal.kernel.dao.orm.SQLQuery;
031 import com.liferay.portal.kernel.dao.orm.Session;
032 import com.liferay.portal.kernel.exception.SystemException;
033 import com.liferay.portal.kernel.log.Log;
034 import com.liferay.portal.kernel.log.LogFactoryUtil;
035 import com.liferay.portal.kernel.util.ArrayUtil;
036 import com.liferay.portal.kernel.util.GetterUtil;
037 import com.liferay.portal.kernel.util.InstanceFactory;
038 import com.liferay.portal.kernel.util.OrderByComparator;
039 import com.liferay.portal.kernel.util.SetUtil;
040 import com.liferay.portal.kernel.util.StringBundler;
041 import com.liferay.portal.kernel.util.StringPool;
042 import com.liferay.portal.kernel.util.StringUtil;
043 import com.liferay.portal.kernel.util.UnmodifiableList;
044 import com.liferay.portal.kernel.util.Validator;
045 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
046 import com.liferay.portal.model.CacheModel;
047 import com.liferay.portal.model.ModelListener;
048 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
049 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050
051 import com.liferay.portlet.asset.NoSuchCategoryException;
052 import com.liferay.portlet.asset.model.AssetCategory;
053 import com.liferay.portlet.asset.model.impl.AssetCategoryImpl;
054 import com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl;
055
056 import java.io.Serializable;
057
058 import java.util.ArrayList;
059 import java.util.Collections;
060 import java.util.List;
061 import java.util.Set;
062
063
075 public class AssetCategoryPersistenceImpl extends BasePersistenceImpl<AssetCategory>
076 implements AssetCategoryPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
088 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
089 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090 "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
092 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
093 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
094 "findAll", new String[0]);
095 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
096 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
099 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
100 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
101 "findByUuid",
102 new String[] {
103 String.class.getName(),
104
105 Integer.class.getName(), Integer.class.getName(),
106 OrderByComparator.class.getName()
107 });
108 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
109 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
110 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
111 "findByUuid", new String[] { String.class.getName() },
112 AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
113 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
114 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
115 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117 new String[] { String.class.getName() });
118
119
126 public List<AssetCategory> findByUuid(String uuid)
127 throws SystemException {
128 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
129 }
130
131
144 public List<AssetCategory> findByUuid(String uuid, int start, int end)
145 throws SystemException {
146 return findByUuid(uuid, start, end, null);
147 }
148
149
163 public List<AssetCategory> findByUuid(String uuid, int start, int end,
164 OrderByComparator orderByComparator) throws SystemException {
165 boolean pagination = true;
166 FinderPath finderPath = null;
167 Object[] finderArgs = null;
168
169 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
170 (orderByComparator == null)) {
171 pagination = false;
172 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
173 finderArgs = new Object[] { uuid };
174 }
175 else {
176 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
177 finderArgs = new Object[] { uuid, start, end, orderByComparator };
178 }
179
180 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
181 finderArgs, this);
182
183 if ((list != null) && !list.isEmpty()) {
184 for (AssetCategory assetCategory : list) {
185 if (!Validator.equals(uuid, assetCategory.getUuid())) {
186 list = null;
187
188 break;
189 }
190 }
191 }
192
193 if (list == null) {
194 StringBundler query = null;
195
196 if (orderByComparator != null) {
197 query = new StringBundler(3 +
198 (orderByComparator.getOrderByFields().length * 3));
199 }
200 else {
201 query = new StringBundler(3);
202 }
203
204 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
205
206 boolean bindUuid = false;
207
208 if (uuid == null) {
209 query.append(_FINDER_COLUMN_UUID_UUID_1);
210 }
211 else if (uuid.equals(StringPool.BLANK)) {
212 query.append(_FINDER_COLUMN_UUID_UUID_3);
213 }
214 else {
215 bindUuid = true;
216
217 query.append(_FINDER_COLUMN_UUID_UUID_2);
218 }
219
220 if (orderByComparator != null) {
221 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
222 orderByComparator);
223 }
224 else
225 if (pagination) {
226 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
227 }
228
229 String sql = query.toString();
230
231 Session session = null;
232
233 try {
234 session = openSession();
235
236 Query q = session.createQuery(sql);
237
238 QueryPos qPos = QueryPos.getInstance(q);
239
240 if (bindUuid) {
241 qPos.add(uuid);
242 }
243
244 if (!pagination) {
245 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
246 start, end, false);
247
248 Collections.sort(list);
249
250 list = new UnmodifiableList<AssetCategory>(list);
251 }
252 else {
253 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
254 start, end);
255 }
256
257 cacheResult(list);
258
259 FinderCacheUtil.putResult(finderPath, finderArgs, list);
260 }
261 catch (Exception e) {
262 FinderCacheUtil.removeResult(finderPath, finderArgs);
263
264 throw processException(e);
265 }
266 finally {
267 closeSession(session);
268 }
269 }
270
271 return list;
272 }
273
274
283 public AssetCategory findByUuid_First(String uuid,
284 OrderByComparator orderByComparator)
285 throws NoSuchCategoryException, SystemException {
286 AssetCategory assetCategory = fetchByUuid_First(uuid, orderByComparator);
287
288 if (assetCategory != null) {
289 return assetCategory;
290 }
291
292 StringBundler msg = new StringBundler(4);
293
294 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
295
296 msg.append("uuid=");
297 msg.append(uuid);
298
299 msg.append(StringPool.CLOSE_CURLY_BRACE);
300
301 throw new NoSuchCategoryException(msg.toString());
302 }
303
304
312 public AssetCategory fetchByUuid_First(String uuid,
313 OrderByComparator orderByComparator) throws SystemException {
314 List<AssetCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
315
316 if (!list.isEmpty()) {
317 return list.get(0);
318 }
319
320 return null;
321 }
322
323
332 public AssetCategory findByUuid_Last(String uuid,
333 OrderByComparator orderByComparator)
334 throws NoSuchCategoryException, SystemException {
335 AssetCategory assetCategory = fetchByUuid_Last(uuid, orderByComparator);
336
337 if (assetCategory != null) {
338 return assetCategory;
339 }
340
341 StringBundler msg = new StringBundler(4);
342
343 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344
345 msg.append("uuid=");
346 msg.append(uuid);
347
348 msg.append(StringPool.CLOSE_CURLY_BRACE);
349
350 throw new NoSuchCategoryException(msg.toString());
351 }
352
353
361 public AssetCategory fetchByUuid_Last(String uuid,
362 OrderByComparator orderByComparator) throws SystemException {
363 int count = countByUuid(uuid);
364
365 List<AssetCategory> list = findByUuid(uuid, count - 1, count,
366 orderByComparator);
367
368 if (!list.isEmpty()) {
369 return list.get(0);
370 }
371
372 return null;
373 }
374
375
385 public AssetCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
386 OrderByComparator orderByComparator)
387 throws NoSuchCategoryException, SystemException {
388 AssetCategory assetCategory = findByPrimaryKey(categoryId);
389
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 AssetCategory[] array = new AssetCategoryImpl[3];
396
397 array[0] = getByUuid_PrevAndNext(session, assetCategory, uuid,
398 orderByComparator, true);
399
400 array[1] = assetCategory;
401
402 array[2] = getByUuid_PrevAndNext(session, assetCategory, uuid,
403 orderByComparator, false);
404
405 return array;
406 }
407 catch (Exception e) {
408 throw processException(e);
409 }
410 finally {
411 closeSession(session);
412 }
413 }
414
415 protected AssetCategory getByUuid_PrevAndNext(Session session,
416 AssetCategory assetCategory, String uuid,
417 OrderByComparator orderByComparator, boolean previous) {
418 StringBundler query = null;
419
420 if (orderByComparator != null) {
421 query = new StringBundler(6 +
422 (orderByComparator.getOrderByFields().length * 6));
423 }
424 else {
425 query = new StringBundler(3);
426 }
427
428 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
429
430 boolean bindUuid = false;
431
432 if (uuid == null) {
433 query.append(_FINDER_COLUMN_UUID_UUID_1);
434 }
435 else if (uuid.equals(StringPool.BLANK)) {
436 query.append(_FINDER_COLUMN_UUID_UUID_3);
437 }
438 else {
439 bindUuid = true;
440
441 query.append(_FINDER_COLUMN_UUID_UUID_2);
442 }
443
444 if (orderByComparator != null) {
445 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446
447 if (orderByConditionFields.length > 0) {
448 query.append(WHERE_AND);
449 }
450
451 for (int i = 0; i < orderByConditionFields.length; i++) {
452 query.append(_ORDER_BY_ENTITY_ALIAS);
453 query.append(orderByConditionFields[i]);
454
455 if ((i + 1) < orderByConditionFields.length) {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN_HAS_NEXT);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN_HAS_NEXT);
461 }
462 }
463 else {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN);
469 }
470 }
471 }
472
473 query.append(ORDER_BY_CLAUSE);
474
475 String[] orderByFields = orderByComparator.getOrderByFields();
476
477 for (int i = 0; i < orderByFields.length; i++) {
478 query.append(_ORDER_BY_ENTITY_ALIAS);
479 query.append(orderByFields[i]);
480
481 if ((i + 1) < orderByFields.length) {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC_HAS_NEXT);
484 }
485 else {
486 query.append(ORDER_BY_DESC_HAS_NEXT);
487 }
488 }
489 else {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC);
492 }
493 else {
494 query.append(ORDER_BY_DESC);
495 }
496 }
497 }
498 }
499 else {
500 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
501 }
502
503 String sql = query.toString();
504
505 Query q = session.createQuery(sql);
506
507 q.setFirstResult(0);
508 q.setMaxResults(2);
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 if (bindUuid) {
513 qPos.add(uuid);
514 }
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<AssetCategory> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
540 public void removeByUuid(String uuid) throws SystemException {
541 for (AssetCategory assetCategory : findByUuid(uuid, QueryUtil.ALL_POS,
542 QueryUtil.ALL_POS, null)) {
543 remove(assetCategory);
544 }
545 }
546
547
554 public int countByUuid(String uuid) throws SystemException {
555 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
556
557 Object[] finderArgs = new Object[] { uuid };
558
559 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
560 this);
561
562 if (count == null) {
563 StringBundler query = new StringBundler(2);
564
565 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
566
567 boolean bindUuid = false;
568
569 if (uuid == null) {
570 query.append(_FINDER_COLUMN_UUID_UUID_1);
571 }
572 else if (uuid.equals(StringPool.BLANK)) {
573 query.append(_FINDER_COLUMN_UUID_UUID_3);
574 }
575 else {
576 bindUuid = true;
577
578 query.append(_FINDER_COLUMN_UUID_UUID_2);
579 }
580
581 String sql = query.toString();
582
583 Session session = null;
584
585 try {
586 session = openSession();
587
588 Query q = session.createQuery(sql);
589
590 QueryPos qPos = QueryPos.getInstance(q);
591
592 if (bindUuid) {
593 qPos.add(uuid);
594 }
595
596 count = (Long)q.uniqueResult();
597
598 FinderCacheUtil.putResult(finderPath, finderArgs, count);
599 }
600 catch (Exception e) {
601 FinderCacheUtil.removeResult(finderPath, finderArgs);
602
603 throw processException(e);
604 }
605 finally {
606 closeSession(session);
607 }
608 }
609
610 return count.intValue();
611 }
612
613 private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetCategory.uuid IS NULL";
614 private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetCategory.uuid = ?";
615 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '')";
616 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
617 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
618 AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
619 new String[] { String.class.getName(), Long.class.getName() },
620 AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
621 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK);
622 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
623 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
624 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
625 new String[] { String.class.getName(), Long.class.getName() });
626
627
636 public AssetCategory findByUUID_G(String uuid, long groupId)
637 throws NoSuchCategoryException, SystemException {
638 AssetCategory assetCategory = fetchByUUID_G(uuid, groupId);
639
640 if (assetCategory == null) {
641 StringBundler msg = new StringBundler(6);
642
643 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644
645 msg.append("uuid=");
646 msg.append(uuid);
647
648 msg.append(", groupId=");
649 msg.append(groupId);
650
651 msg.append(StringPool.CLOSE_CURLY_BRACE);
652
653 if (_log.isWarnEnabled()) {
654 _log.warn(msg.toString());
655 }
656
657 throw new NoSuchCategoryException(msg.toString());
658 }
659
660 return assetCategory;
661 }
662
663
671 public AssetCategory fetchByUUID_G(String uuid, long groupId)
672 throws SystemException {
673 return fetchByUUID_G(uuid, groupId, true);
674 }
675
676
685 public AssetCategory fetchByUUID_G(String uuid, long groupId,
686 boolean retrieveFromCache) throws SystemException {
687 Object[] finderArgs = new Object[] { uuid, groupId };
688
689 Object result = null;
690
691 if (retrieveFromCache) {
692 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
693 finderArgs, this);
694 }
695
696 if (result instanceof AssetCategory) {
697 AssetCategory assetCategory = (AssetCategory)result;
698
699 if (!Validator.equals(uuid, assetCategory.getUuid()) ||
700 (groupId != assetCategory.getGroupId())) {
701 result = null;
702 }
703 }
704
705 if (result == null) {
706 StringBundler query = new StringBundler(4);
707
708 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
709
710 boolean bindUuid = false;
711
712 if (uuid == null) {
713 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
714 }
715 else if (uuid.equals(StringPool.BLANK)) {
716 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
717 }
718 else {
719 bindUuid = true;
720
721 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
722 }
723
724 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
725
726 String sql = query.toString();
727
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 Query q = session.createQuery(sql);
734
735 QueryPos qPos = QueryPos.getInstance(q);
736
737 if (bindUuid) {
738 qPos.add(uuid);
739 }
740
741 qPos.add(groupId);
742
743 List<AssetCategory> list = q.list();
744
745 if (list.isEmpty()) {
746 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
747 finderArgs, list);
748 }
749 else {
750 AssetCategory assetCategory = list.get(0);
751
752 result = assetCategory;
753
754 cacheResult(assetCategory);
755
756 if ((assetCategory.getUuid() == null) ||
757 !assetCategory.getUuid().equals(uuid) ||
758 (assetCategory.getGroupId() != groupId)) {
759 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
760 finderArgs, assetCategory);
761 }
762 }
763 }
764 catch (Exception e) {
765 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
766 finderArgs);
767
768 throw processException(e);
769 }
770 finally {
771 closeSession(session);
772 }
773 }
774
775 if (result instanceof List<?>) {
776 return null;
777 }
778 else {
779 return (AssetCategory)result;
780 }
781 }
782
783
791 public AssetCategory removeByUUID_G(String uuid, long groupId)
792 throws NoSuchCategoryException, SystemException {
793 AssetCategory assetCategory = findByUUID_G(uuid, groupId);
794
795 return remove(assetCategory);
796 }
797
798
806 public int countByUUID_G(String uuid, long groupId)
807 throws SystemException {
808 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
809
810 Object[] finderArgs = new Object[] { uuid, groupId };
811
812 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
813 this);
814
815 if (count == null) {
816 StringBundler query = new StringBundler(3);
817
818 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
819
820 boolean bindUuid = false;
821
822 if (uuid == null) {
823 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
824 }
825 else if (uuid.equals(StringPool.BLANK)) {
826 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
827 }
828 else {
829 bindUuid = true;
830
831 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
832 }
833
834 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
835
836 String sql = query.toString();
837
838 Session session = null;
839
840 try {
841 session = openSession();
842
843 Query q = session.createQuery(sql);
844
845 QueryPos qPos = QueryPos.getInstance(q);
846
847 if (bindUuid) {
848 qPos.add(uuid);
849 }
850
851 qPos.add(groupId);
852
853 count = (Long)q.uniqueResult();
854
855 FinderCacheUtil.putResult(finderPath, finderArgs, count);
856 }
857 catch (Exception e) {
858 FinderCacheUtil.removeResult(finderPath, finderArgs);
859
860 throw processException(e);
861 }
862 finally {
863 closeSession(session);
864 }
865 }
866
867 return count.intValue();
868 }
869
870 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetCategory.uuid IS NULL AND ";
871 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetCategory.uuid = ? AND ";
872 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '') AND ";
873 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetCategory.groupId = ?";
874 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
875 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
876 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
877 "findByUuid_C",
878 new String[] {
879 String.class.getName(), Long.class.getName(),
880
881 Integer.class.getName(), Integer.class.getName(),
882 OrderByComparator.class.getName()
883 });
884 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
885 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
886 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
887 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
888 "findByUuid_C",
889 new String[] { String.class.getName(), Long.class.getName() },
890 AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
891 AssetCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
892 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
893 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
894 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
895 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
896 new String[] { String.class.getName(), Long.class.getName() });
897
898
906 public List<AssetCategory> findByUuid_C(String uuid, long companyId)
907 throws SystemException {
908 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
909 QueryUtil.ALL_POS, null);
910 }
911
912
926 public List<AssetCategory> findByUuid_C(String uuid, long companyId,
927 int start, int end) throws SystemException {
928 return findByUuid_C(uuid, companyId, start, end, null);
929 }
930
931
946 public List<AssetCategory> findByUuid_C(String uuid, long companyId,
947 int start, int end, OrderByComparator orderByComparator)
948 throws SystemException {
949 boolean pagination = true;
950 FinderPath finderPath = null;
951 Object[] finderArgs = null;
952
953 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
954 (orderByComparator == null)) {
955 pagination = false;
956 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
957 finderArgs = new Object[] { uuid, companyId };
958 }
959 else {
960 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
961 finderArgs = new Object[] {
962 uuid, companyId,
963
964 start, end, orderByComparator
965 };
966 }
967
968 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
969 finderArgs, this);
970
971 if ((list != null) && !list.isEmpty()) {
972 for (AssetCategory assetCategory : list) {
973 if (!Validator.equals(uuid, assetCategory.getUuid()) ||
974 (companyId != assetCategory.getCompanyId())) {
975 list = null;
976
977 break;
978 }
979 }
980 }
981
982 if (list == null) {
983 StringBundler query = null;
984
985 if (orderByComparator != null) {
986 query = new StringBundler(4 +
987 (orderByComparator.getOrderByFields().length * 3));
988 }
989 else {
990 query = new StringBundler(4);
991 }
992
993 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
994
995 boolean bindUuid = false;
996
997 if (uuid == null) {
998 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
999 }
1000 else if (uuid.equals(StringPool.BLANK)) {
1001 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1002 }
1003 else {
1004 bindUuid = true;
1005
1006 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1007 }
1008
1009 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1010
1011 if (orderByComparator != null) {
1012 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1013 orderByComparator);
1014 }
1015 else
1016 if (pagination) {
1017 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1018 }
1019
1020 String sql = query.toString();
1021
1022 Session session = null;
1023
1024 try {
1025 session = openSession();
1026
1027 Query q = session.createQuery(sql);
1028
1029 QueryPos qPos = QueryPos.getInstance(q);
1030
1031 if (bindUuid) {
1032 qPos.add(uuid);
1033 }
1034
1035 qPos.add(companyId);
1036
1037 if (!pagination) {
1038 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1039 start, end, false);
1040
1041 Collections.sort(list);
1042
1043 list = new UnmodifiableList<AssetCategory>(list);
1044 }
1045 else {
1046 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1047 start, end);
1048 }
1049
1050 cacheResult(list);
1051
1052 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1053 }
1054 catch (Exception e) {
1055 FinderCacheUtil.removeResult(finderPath, finderArgs);
1056
1057 throw processException(e);
1058 }
1059 finally {
1060 closeSession(session);
1061 }
1062 }
1063
1064 return list;
1065 }
1066
1067
1077 public AssetCategory findByUuid_C_First(String uuid, long companyId,
1078 OrderByComparator orderByComparator)
1079 throws NoSuchCategoryException, SystemException {
1080 AssetCategory assetCategory = fetchByUuid_C_First(uuid, companyId,
1081 orderByComparator);
1082
1083 if (assetCategory != null) {
1084 return assetCategory;
1085 }
1086
1087 StringBundler msg = new StringBundler(6);
1088
1089 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1090
1091 msg.append("uuid=");
1092 msg.append(uuid);
1093
1094 msg.append(", companyId=");
1095 msg.append(companyId);
1096
1097 msg.append(StringPool.CLOSE_CURLY_BRACE);
1098
1099 throw new NoSuchCategoryException(msg.toString());
1100 }
1101
1102
1111 public AssetCategory fetchByUuid_C_First(String uuid, long companyId,
1112 OrderByComparator orderByComparator) throws SystemException {
1113 List<AssetCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1114 orderByComparator);
1115
1116 if (!list.isEmpty()) {
1117 return list.get(0);
1118 }
1119
1120 return null;
1121 }
1122
1123
1133 public AssetCategory findByUuid_C_Last(String uuid, long companyId,
1134 OrderByComparator orderByComparator)
1135 throws NoSuchCategoryException, SystemException {
1136 AssetCategory assetCategory = fetchByUuid_C_Last(uuid, companyId,
1137 orderByComparator);
1138
1139 if (assetCategory != null) {
1140 return assetCategory;
1141 }
1142
1143 StringBundler msg = new StringBundler(6);
1144
1145 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1146
1147 msg.append("uuid=");
1148 msg.append(uuid);
1149
1150 msg.append(", companyId=");
1151 msg.append(companyId);
1152
1153 msg.append(StringPool.CLOSE_CURLY_BRACE);
1154
1155 throw new NoSuchCategoryException(msg.toString());
1156 }
1157
1158
1167 public AssetCategory fetchByUuid_C_Last(String uuid, long companyId,
1168 OrderByComparator orderByComparator) throws SystemException {
1169 int count = countByUuid_C(uuid, companyId);
1170
1171 List<AssetCategory> list = findByUuid_C(uuid, companyId, count - 1,
1172 count, orderByComparator);
1173
1174 if (!list.isEmpty()) {
1175 return list.get(0);
1176 }
1177
1178 return null;
1179 }
1180
1181
1192 public AssetCategory[] findByUuid_C_PrevAndNext(long categoryId,
1193 String uuid, long companyId, OrderByComparator orderByComparator)
1194 throws NoSuchCategoryException, SystemException {
1195 AssetCategory assetCategory = findByPrimaryKey(categoryId);
1196
1197 Session session = null;
1198
1199 try {
1200 session = openSession();
1201
1202 AssetCategory[] array = new AssetCategoryImpl[3];
1203
1204 array[0] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1205 companyId, orderByComparator, true);
1206
1207 array[1] = assetCategory;
1208
1209 array[2] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1210 companyId, orderByComparator, false);
1211
1212 return array;
1213 }
1214 catch (Exception e) {
1215 throw processException(e);
1216 }
1217 finally {
1218 closeSession(session);
1219 }
1220 }
1221
1222 protected AssetCategory getByUuid_C_PrevAndNext(Session session,
1223 AssetCategory assetCategory, String uuid, long companyId,
1224 OrderByComparator orderByComparator, boolean previous) {
1225 StringBundler query = null;
1226
1227 if (orderByComparator != null) {
1228 query = new StringBundler(6 +
1229 (orderByComparator.getOrderByFields().length * 6));
1230 }
1231 else {
1232 query = new StringBundler(3);
1233 }
1234
1235 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1236
1237 boolean bindUuid = false;
1238
1239 if (uuid == null) {
1240 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1241 }
1242 else if (uuid.equals(StringPool.BLANK)) {
1243 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1244 }
1245 else {
1246 bindUuid = true;
1247
1248 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1249 }
1250
1251 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1252
1253 if (orderByComparator != null) {
1254 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1255
1256 if (orderByConditionFields.length > 0) {
1257 query.append(WHERE_AND);
1258 }
1259
1260 for (int i = 0; i < orderByConditionFields.length; i++) {
1261 query.append(_ORDER_BY_ENTITY_ALIAS);
1262 query.append(orderByConditionFields[i]);
1263
1264 if ((i + 1) < orderByConditionFields.length) {
1265 if (orderByComparator.isAscending() ^ previous) {
1266 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1267 }
1268 else {
1269 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1270 }
1271 }
1272 else {
1273 if (orderByComparator.isAscending() ^ previous) {
1274 query.append(WHERE_GREATER_THAN);
1275 }
1276 else {
1277 query.append(WHERE_LESSER_THAN);
1278 }
1279 }
1280 }
1281
1282 query.append(ORDER_BY_CLAUSE);
1283
1284 String[] orderByFields = orderByComparator.getOrderByFields();
1285
1286 for (int i = 0; i < orderByFields.length; i++) {
1287 query.append(_ORDER_BY_ENTITY_ALIAS);
1288 query.append(orderByFields[i]);
1289
1290 if ((i + 1) < orderByFields.length) {
1291 if (orderByComparator.isAscending() ^ previous) {
1292 query.append(ORDER_BY_ASC_HAS_NEXT);
1293 }
1294 else {
1295 query.append(ORDER_BY_DESC_HAS_NEXT);
1296 }
1297 }
1298 else {
1299 if (orderByComparator.isAscending() ^ previous) {
1300 query.append(ORDER_BY_ASC);
1301 }
1302 else {
1303 query.append(ORDER_BY_DESC);
1304 }
1305 }
1306 }
1307 }
1308 else {
1309 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1310 }
1311
1312 String sql = query.toString();
1313
1314 Query q = session.createQuery(sql);
1315
1316 q.setFirstResult(0);
1317 q.setMaxResults(2);
1318
1319 QueryPos qPos = QueryPos.getInstance(q);
1320
1321 if (bindUuid) {
1322 qPos.add(uuid);
1323 }
1324
1325 qPos.add(companyId);
1326
1327 if (orderByComparator != null) {
1328 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1329
1330 for (Object value : values) {
1331 qPos.add(value);
1332 }
1333 }
1334
1335 List<AssetCategory> list = q.list();
1336
1337 if (list.size() == 2) {
1338 return list.get(1);
1339 }
1340 else {
1341 return null;
1342 }
1343 }
1344
1345
1352 public void removeByUuid_C(String uuid, long companyId)
1353 throws SystemException {
1354 for (AssetCategory assetCategory : findByUuid_C(uuid, companyId,
1355 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1356 remove(assetCategory);
1357 }
1358 }
1359
1360
1368 public int countByUuid_C(String uuid, long companyId)
1369 throws SystemException {
1370 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1371
1372 Object[] finderArgs = new Object[] { uuid, companyId };
1373
1374 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1375 this);
1376
1377 if (count == null) {
1378 StringBundler query = new StringBundler(3);
1379
1380 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
1381
1382 boolean bindUuid = false;
1383
1384 if (uuid == null) {
1385 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1386 }
1387 else if (uuid.equals(StringPool.BLANK)) {
1388 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1389 }
1390 else {
1391 bindUuid = true;
1392
1393 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1394 }
1395
1396 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1397
1398 String sql = query.toString();
1399
1400 Session session = null;
1401
1402 try {
1403 session = openSession();
1404
1405 Query q = session.createQuery(sql);
1406
1407 QueryPos qPos = QueryPos.getInstance(q);
1408
1409 if (bindUuid) {
1410 qPos.add(uuid);
1411 }
1412
1413 qPos.add(companyId);
1414
1415 count = (Long)q.uniqueResult();
1416
1417 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1418 }
1419 catch (Exception e) {
1420 FinderCacheUtil.removeResult(finderPath, finderArgs);
1421
1422 throw processException(e);
1423 }
1424 finally {
1425 closeSession(session);
1426 }
1427 }
1428
1429 return count.intValue();
1430 }
1431
1432 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "assetCategory.uuid IS NULL AND ";
1433 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "assetCategory.uuid = ? AND ";
1434 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '') AND ";
1435 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "assetCategory.companyId = ?";
1436 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1437 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1438 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1439 "findByGroupId",
1440 new String[] {
1441 Long.class.getName(),
1442
1443 Integer.class.getName(), Integer.class.getName(),
1444 OrderByComparator.class.getName()
1445 });
1446 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1447 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1448 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1449 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1450 "findByGroupId", new String[] { Long.class.getName() },
1451 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1452 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
1453 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1454 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1455 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1456 new String[] { Long.class.getName() });
1457
1458
1465 public List<AssetCategory> findByGroupId(long groupId)
1466 throws SystemException {
1467 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1468 }
1469
1470
1483 public List<AssetCategory> findByGroupId(long groupId, int start, int end)
1484 throws SystemException {
1485 return findByGroupId(groupId, start, end, null);
1486 }
1487
1488
1502 public List<AssetCategory> findByGroupId(long groupId, int start, int end,
1503 OrderByComparator orderByComparator) throws SystemException {
1504 boolean pagination = true;
1505 FinderPath finderPath = null;
1506 Object[] finderArgs = null;
1507
1508 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1509 (orderByComparator == null)) {
1510 pagination = false;
1511 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1512 finderArgs = new Object[] { groupId };
1513 }
1514 else {
1515 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1516 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1517 }
1518
1519 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
1520 finderArgs, this);
1521
1522 if ((list != null) && !list.isEmpty()) {
1523 for (AssetCategory assetCategory : list) {
1524 if ((groupId != assetCategory.getGroupId())) {
1525 list = null;
1526
1527 break;
1528 }
1529 }
1530 }
1531
1532 if (list == null) {
1533 StringBundler query = null;
1534
1535 if (orderByComparator != null) {
1536 query = new StringBundler(3 +
1537 (orderByComparator.getOrderByFields().length * 3));
1538 }
1539 else {
1540 query = new StringBundler(3);
1541 }
1542
1543 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1544
1545 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1546
1547 if (orderByComparator != null) {
1548 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1549 orderByComparator);
1550 }
1551 else
1552 if (pagination) {
1553 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1554 }
1555
1556 String sql = query.toString();
1557
1558 Session session = null;
1559
1560 try {
1561 session = openSession();
1562
1563 Query q = session.createQuery(sql);
1564
1565 QueryPos qPos = QueryPos.getInstance(q);
1566
1567 qPos.add(groupId);
1568
1569 if (!pagination) {
1570 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1571 start, end, false);
1572
1573 Collections.sort(list);
1574
1575 list = new UnmodifiableList<AssetCategory>(list);
1576 }
1577 else {
1578 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1579 start, end);
1580 }
1581
1582 cacheResult(list);
1583
1584 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1585 }
1586 catch (Exception e) {
1587 FinderCacheUtil.removeResult(finderPath, finderArgs);
1588
1589 throw processException(e);
1590 }
1591 finally {
1592 closeSession(session);
1593 }
1594 }
1595
1596 return list;
1597 }
1598
1599
1608 public AssetCategory findByGroupId_First(long groupId,
1609 OrderByComparator orderByComparator)
1610 throws NoSuchCategoryException, SystemException {
1611 AssetCategory assetCategory = fetchByGroupId_First(groupId,
1612 orderByComparator);
1613
1614 if (assetCategory != null) {
1615 return assetCategory;
1616 }
1617
1618 StringBundler msg = new StringBundler(4);
1619
1620 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1621
1622 msg.append("groupId=");
1623 msg.append(groupId);
1624
1625 msg.append(StringPool.CLOSE_CURLY_BRACE);
1626
1627 throw new NoSuchCategoryException(msg.toString());
1628 }
1629
1630
1638 public AssetCategory fetchByGroupId_First(long groupId,
1639 OrderByComparator orderByComparator) throws SystemException {
1640 List<AssetCategory> list = findByGroupId(groupId, 0, 1,
1641 orderByComparator);
1642
1643 if (!list.isEmpty()) {
1644 return list.get(0);
1645 }
1646
1647 return null;
1648 }
1649
1650
1659 public AssetCategory findByGroupId_Last(long groupId,
1660 OrderByComparator orderByComparator)
1661 throws NoSuchCategoryException, SystemException {
1662 AssetCategory assetCategory = fetchByGroupId_Last(groupId,
1663 orderByComparator);
1664
1665 if (assetCategory != null) {
1666 return assetCategory;
1667 }
1668
1669 StringBundler msg = new StringBundler(4);
1670
1671 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1672
1673 msg.append("groupId=");
1674 msg.append(groupId);
1675
1676 msg.append(StringPool.CLOSE_CURLY_BRACE);
1677
1678 throw new NoSuchCategoryException(msg.toString());
1679 }
1680
1681
1689 public AssetCategory fetchByGroupId_Last(long groupId,
1690 OrderByComparator orderByComparator) throws SystemException {
1691 int count = countByGroupId(groupId);
1692
1693 List<AssetCategory> list = findByGroupId(groupId, count - 1, count,
1694 orderByComparator);
1695
1696 if (!list.isEmpty()) {
1697 return list.get(0);
1698 }
1699
1700 return null;
1701 }
1702
1703
1713 public AssetCategory[] findByGroupId_PrevAndNext(long categoryId,
1714 long groupId, OrderByComparator orderByComparator)
1715 throws NoSuchCategoryException, SystemException {
1716 AssetCategory assetCategory = findByPrimaryKey(categoryId);
1717
1718 Session session = null;
1719
1720 try {
1721 session = openSession();
1722
1723 AssetCategory[] array = new AssetCategoryImpl[3];
1724
1725 array[0] = getByGroupId_PrevAndNext(session, assetCategory,
1726 groupId, orderByComparator, true);
1727
1728 array[1] = assetCategory;
1729
1730 array[2] = getByGroupId_PrevAndNext(session, assetCategory,
1731 groupId, orderByComparator, false);
1732
1733 return array;
1734 }
1735 catch (Exception e) {
1736 throw processException(e);
1737 }
1738 finally {
1739 closeSession(session);
1740 }
1741 }
1742
1743 protected AssetCategory getByGroupId_PrevAndNext(Session session,
1744 AssetCategory assetCategory, long groupId,
1745 OrderByComparator orderByComparator, boolean previous) {
1746 StringBundler query = null;
1747
1748 if (orderByComparator != null) {
1749 query = new StringBundler(6 +
1750 (orderByComparator.getOrderByFields().length * 6));
1751 }
1752 else {
1753 query = new StringBundler(3);
1754 }
1755
1756 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1757
1758 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1759
1760 if (orderByComparator != null) {
1761 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1762
1763 if (orderByConditionFields.length > 0) {
1764 query.append(WHERE_AND);
1765 }
1766
1767 for (int i = 0; i < orderByConditionFields.length; i++) {
1768 query.append(_ORDER_BY_ENTITY_ALIAS);
1769 query.append(orderByConditionFields[i]);
1770
1771 if ((i + 1) < orderByConditionFields.length) {
1772 if (orderByComparator.isAscending() ^ previous) {
1773 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1774 }
1775 else {
1776 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1777 }
1778 }
1779 else {
1780 if (orderByComparator.isAscending() ^ previous) {
1781 query.append(WHERE_GREATER_THAN);
1782 }
1783 else {
1784 query.append(WHERE_LESSER_THAN);
1785 }
1786 }
1787 }
1788
1789 query.append(ORDER_BY_CLAUSE);
1790
1791 String[] orderByFields = orderByComparator.getOrderByFields();
1792
1793 for (int i = 0; i < orderByFields.length; i++) {
1794 query.append(_ORDER_BY_ENTITY_ALIAS);
1795 query.append(orderByFields[i]);
1796
1797 if ((i + 1) < orderByFields.length) {
1798 if (orderByComparator.isAscending() ^ previous) {
1799 query.append(ORDER_BY_ASC_HAS_NEXT);
1800 }
1801 else {
1802 query.append(ORDER_BY_DESC_HAS_NEXT);
1803 }
1804 }
1805 else {
1806 if (orderByComparator.isAscending() ^ previous) {
1807 query.append(ORDER_BY_ASC);
1808 }
1809 else {
1810 query.append(ORDER_BY_DESC);
1811 }
1812 }
1813 }
1814 }
1815 else {
1816 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1817 }
1818
1819 String sql = query.toString();
1820
1821 Query q = session.createQuery(sql);
1822
1823 q.setFirstResult(0);
1824 q.setMaxResults(2);
1825
1826 QueryPos qPos = QueryPos.getInstance(q);
1827
1828 qPos.add(groupId);
1829
1830 if (orderByComparator != null) {
1831 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1832
1833 for (Object value : values) {
1834 qPos.add(value);
1835 }
1836 }
1837
1838 List<AssetCategory> list = q.list();
1839
1840 if (list.size() == 2) {
1841 return list.get(1);
1842 }
1843 else {
1844 return null;
1845 }
1846 }
1847
1848
1855 public List<AssetCategory> filterFindByGroupId(long groupId)
1856 throws SystemException {
1857 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1858 QueryUtil.ALL_POS, null);
1859 }
1860
1861
1874 public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1875 int end) throws SystemException {
1876 return filterFindByGroupId(groupId, start, end, null);
1877 }
1878
1879
1893 public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1894 int end, OrderByComparator orderByComparator) throws SystemException {
1895 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1896 return findByGroupId(groupId, start, end, orderByComparator);
1897 }
1898
1899 StringBundler query = null;
1900
1901 if (orderByComparator != null) {
1902 query = new StringBundler(3 +
1903 (orderByComparator.getOrderByFields().length * 3));
1904 }
1905 else {
1906 query = new StringBundler(3);
1907 }
1908
1909 if (getDB().isSupportsInlineDistinct()) {
1910 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
1911 }
1912 else {
1913 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1914 }
1915
1916 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1917
1918 if (!getDB().isSupportsInlineDistinct()) {
1919 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1920 }
1921
1922 if (orderByComparator != null) {
1923 if (getDB().isSupportsInlineDistinct()) {
1924 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1925 orderByComparator);
1926 }
1927 else {
1928 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1929 orderByComparator);
1930 }
1931 }
1932 else {
1933 if (getDB().isSupportsInlineDistinct()) {
1934 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1935 }
1936 else {
1937 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
1938 }
1939 }
1940
1941 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1942 AssetCategory.class.getName(),
1943 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1944
1945 Session session = null;
1946
1947 try {
1948 session = openSession();
1949
1950 SQLQuery q = session.createSQLQuery(sql);
1951
1952 if (getDB().isSupportsInlineDistinct()) {
1953 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
1954 }
1955 else {
1956 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
1957 }
1958
1959 QueryPos qPos = QueryPos.getInstance(q);
1960
1961 qPos.add(groupId);
1962
1963 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
1964 end);
1965 }
1966 catch (Exception e) {
1967 throw processException(e);
1968 }
1969 finally {
1970 closeSession(session);
1971 }
1972 }
1973
1974
1984 public AssetCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
1985 long groupId, OrderByComparator orderByComparator)
1986 throws NoSuchCategoryException, SystemException {
1987 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1988 return findByGroupId_PrevAndNext(categoryId, groupId,
1989 orderByComparator);
1990 }
1991
1992 AssetCategory assetCategory = findByPrimaryKey(categoryId);
1993
1994 Session session = null;
1995
1996 try {
1997 session = openSession();
1998
1999 AssetCategory[] array = new AssetCategoryImpl[3];
2000
2001 array[0] = filterGetByGroupId_PrevAndNext(session, assetCategory,
2002 groupId, orderByComparator, true);
2003
2004 array[1] = assetCategory;
2005
2006 array[2] = filterGetByGroupId_PrevAndNext(session, assetCategory,
2007 groupId, orderByComparator, false);
2008
2009 return array;
2010 }
2011 catch (Exception e) {
2012 throw processException(e);
2013 }
2014 finally {
2015 closeSession(session);
2016 }
2017 }
2018
2019 protected AssetCategory filterGetByGroupId_PrevAndNext(Session session,
2020 AssetCategory assetCategory, long groupId,
2021 OrderByComparator orderByComparator, boolean previous) {
2022 StringBundler query = null;
2023
2024 if (orderByComparator != null) {
2025 query = new StringBundler(6 +
2026 (orderByComparator.getOrderByFields().length * 6));
2027 }
2028 else {
2029 query = new StringBundler(3);
2030 }
2031
2032 if (getDB().isSupportsInlineDistinct()) {
2033 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
2034 }
2035 else {
2036 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2037 }
2038
2039 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2040
2041 if (!getDB().isSupportsInlineDistinct()) {
2042 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2043 }
2044
2045 if (orderByComparator != null) {
2046 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2047
2048 if (orderByConditionFields.length > 0) {
2049 query.append(WHERE_AND);
2050 }
2051
2052 for (int i = 0; i < orderByConditionFields.length; i++) {
2053 if (getDB().isSupportsInlineDistinct()) {
2054 query.append(_ORDER_BY_ENTITY_ALIAS);
2055 }
2056 else {
2057 query.append(_ORDER_BY_ENTITY_TABLE);
2058 }
2059
2060 query.append(orderByConditionFields[i]);
2061
2062 if ((i + 1) < orderByConditionFields.length) {
2063 if (orderByComparator.isAscending() ^ previous) {
2064 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2065 }
2066 else {
2067 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2068 }
2069 }
2070 else {
2071 if (orderByComparator.isAscending() ^ previous) {
2072 query.append(WHERE_GREATER_THAN);
2073 }
2074 else {
2075 query.append(WHERE_LESSER_THAN);
2076 }
2077 }
2078 }
2079
2080 query.append(ORDER_BY_CLAUSE);
2081
2082 String[] orderByFields = orderByComparator.getOrderByFields();
2083
2084 for (int i = 0; i < orderByFields.length; i++) {
2085 if (getDB().isSupportsInlineDistinct()) {
2086 query.append(_ORDER_BY_ENTITY_ALIAS);
2087 }
2088 else {
2089 query.append(_ORDER_BY_ENTITY_TABLE);
2090 }
2091
2092 query.append(orderByFields[i]);
2093
2094 if ((i + 1) < orderByFields.length) {
2095 if (orderByComparator.isAscending() ^ previous) {
2096 query.append(ORDER_BY_ASC_HAS_NEXT);
2097 }
2098 else {
2099 query.append(ORDER_BY_DESC_HAS_NEXT);
2100 }
2101 }
2102 else {
2103 if (orderByComparator.isAscending() ^ previous) {
2104 query.append(ORDER_BY_ASC);
2105 }
2106 else {
2107 query.append(ORDER_BY_DESC);
2108 }
2109 }
2110 }
2111 }
2112 else {
2113 if (getDB().isSupportsInlineDistinct()) {
2114 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2115 }
2116 else {
2117 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
2118 }
2119 }
2120
2121 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2122 AssetCategory.class.getName(),
2123 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2124
2125 SQLQuery q = session.createSQLQuery(sql);
2126
2127 q.setFirstResult(0);
2128 q.setMaxResults(2);
2129
2130 if (getDB().isSupportsInlineDistinct()) {
2131 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
2132 }
2133 else {
2134 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
2135 }
2136
2137 QueryPos qPos = QueryPos.getInstance(q);
2138
2139 qPos.add(groupId);
2140
2141 if (orderByComparator != null) {
2142 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2143
2144 for (Object value : values) {
2145 qPos.add(value);
2146 }
2147 }
2148
2149 List<AssetCategory> list = q.list();
2150
2151 if (list.size() == 2) {
2152 return list.get(1);
2153 }
2154 else {
2155 return null;
2156 }
2157 }
2158
2159
2165 public void removeByGroupId(long groupId) throws SystemException {
2166 for (AssetCategory assetCategory : findByGroupId(groupId,
2167 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2168 remove(assetCategory);
2169 }
2170 }
2171
2172
2179 public int countByGroupId(long groupId) throws SystemException {
2180 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2181
2182 Object[] finderArgs = new Object[] { groupId };
2183
2184 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2185 this);
2186
2187 if (count == null) {
2188 StringBundler query = new StringBundler(2);
2189
2190 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2191
2192 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2193
2194 String sql = query.toString();
2195
2196 Session session = null;
2197
2198 try {
2199 session = openSession();
2200
2201 Query q = session.createQuery(sql);
2202
2203 QueryPos qPos = QueryPos.getInstance(q);
2204
2205 qPos.add(groupId);
2206
2207 count = (Long)q.uniqueResult();
2208
2209 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2210 }
2211 catch (Exception e) {
2212 FinderCacheUtil.removeResult(finderPath, finderArgs);
2213
2214 throw processException(e);
2215 }
2216 finally {
2217 closeSession(session);
2218 }
2219 }
2220
2221 return count.intValue();
2222 }
2223
2224
2231 public int filterCountByGroupId(long groupId) throws SystemException {
2232 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2233 return countByGroupId(groupId);
2234 }
2235
2236 StringBundler query = new StringBundler(2);
2237
2238 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
2239
2240 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2241
2242 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2243 AssetCategory.class.getName(),
2244 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2245
2246 Session session = null;
2247
2248 try {
2249 session = openSession();
2250
2251 SQLQuery q = session.createSQLQuery(sql);
2252
2253 q.addScalar(COUNT_COLUMN_NAME,
2254 com.liferay.portal.kernel.dao.orm.Type.LONG);
2255
2256 QueryPos qPos = QueryPos.getInstance(q);
2257
2258 qPos.add(groupId);
2259
2260 Long count = (Long)q.uniqueResult();
2261
2262 return count.intValue();
2263 }
2264 catch (Exception e) {
2265 throw processException(e);
2266 }
2267 finally {
2268 closeSession(session);
2269 }
2270 }
2271
2272 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetCategory.groupId = ?";
2273 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID =
2274 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2275 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2276 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2277 "findByParentCategoryId",
2278 new String[] {
2279 Long.class.getName(),
2280
2281 Integer.class.getName(), Integer.class.getName(),
2282 OrderByComparator.class.getName()
2283 });
2284 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID =
2285 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2286 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2287 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2288 "findByParentCategoryId", new String[] { Long.class.getName() },
2289 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2290 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2291 public static final FinderPath FINDER_PATH_COUNT_BY_PARENTCATEGORYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2292 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2293 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2294 "countByParentCategoryId", new String[] { Long.class.getName() });
2295
2296
2303 public List<AssetCategory> findByParentCategoryId(long parentCategoryId)
2304 throws SystemException {
2305 return findByParentCategoryId(parentCategoryId, QueryUtil.ALL_POS,
2306 QueryUtil.ALL_POS, null);
2307 }
2308
2309
2322 public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2323 int start, int end) throws SystemException {
2324 return findByParentCategoryId(parentCategoryId, start, end, null);
2325 }
2326
2327
2341 public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2342 int start, int end, OrderByComparator orderByComparator)
2343 throws SystemException {
2344 boolean pagination = true;
2345 FinderPath finderPath = null;
2346 Object[] finderArgs = null;
2347
2348 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2349 (orderByComparator == null)) {
2350 pagination = false;
2351 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID;
2352 finderArgs = new Object[] { parentCategoryId };
2353 }
2354 else {
2355 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID;
2356 finderArgs = new Object[] {
2357 parentCategoryId,
2358
2359 start, end, orderByComparator
2360 };
2361 }
2362
2363 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
2364 finderArgs, this);
2365
2366 if ((list != null) && !list.isEmpty()) {
2367 for (AssetCategory assetCategory : list) {
2368 if ((parentCategoryId != assetCategory.getParentCategoryId())) {
2369 list = null;
2370
2371 break;
2372 }
2373 }
2374 }
2375
2376 if (list == null) {
2377 StringBundler query = null;
2378
2379 if (orderByComparator != null) {
2380 query = new StringBundler(3 +
2381 (orderByComparator.getOrderByFields().length * 3));
2382 }
2383 else {
2384 query = new StringBundler(3);
2385 }
2386
2387 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2388
2389 query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2390
2391 if (orderByComparator != null) {
2392 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2393 orderByComparator);
2394 }
2395 else
2396 if (pagination) {
2397 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2398 }
2399
2400 String sql = query.toString();
2401
2402 Session session = null;
2403
2404 try {
2405 session = openSession();
2406
2407 Query q = session.createQuery(sql);
2408
2409 QueryPos qPos = QueryPos.getInstance(q);
2410
2411 qPos.add(parentCategoryId);
2412
2413 if (!pagination) {
2414 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2415 start, end, false);
2416
2417 Collections.sort(list);
2418
2419 list = new UnmodifiableList<AssetCategory>(list);
2420 }
2421 else {
2422 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2423 start, end);
2424 }
2425
2426 cacheResult(list);
2427
2428 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2429 }
2430 catch (Exception e) {
2431 FinderCacheUtil.removeResult(finderPath, finderArgs);
2432
2433 throw processException(e);
2434 }
2435 finally {
2436 closeSession(session);
2437 }
2438 }
2439
2440 return list;
2441 }
2442
2443
2452 public AssetCategory findByParentCategoryId_First(long parentCategoryId,
2453 OrderByComparator orderByComparator)
2454 throws NoSuchCategoryException, SystemException {
2455 AssetCategory assetCategory = fetchByParentCategoryId_First(parentCategoryId,
2456 orderByComparator);
2457
2458 if (assetCategory != null) {
2459 return assetCategory;
2460 }
2461
2462 StringBundler msg = new StringBundler(4);
2463
2464 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2465
2466 msg.append("parentCategoryId=");
2467 msg.append(parentCategoryId);
2468
2469 msg.append(StringPool.CLOSE_CURLY_BRACE);
2470
2471 throw new NoSuchCategoryException(msg.toString());
2472 }
2473
2474
2482 public AssetCategory fetchByParentCategoryId_First(long parentCategoryId,
2483 OrderByComparator orderByComparator) throws SystemException {
2484 List<AssetCategory> list = findByParentCategoryId(parentCategoryId, 0,
2485 1, orderByComparator);
2486
2487 if (!list.isEmpty()) {
2488 return list.get(0);
2489 }
2490
2491 return null;
2492 }
2493
2494
2503 public AssetCategory findByParentCategoryId_Last(long parentCategoryId,
2504 OrderByComparator orderByComparator)
2505 throws NoSuchCategoryException, SystemException {
2506 AssetCategory assetCategory = fetchByParentCategoryId_Last(parentCategoryId,
2507 orderByComparator);
2508
2509 if (assetCategory != null) {
2510 return assetCategory;
2511 }
2512
2513 StringBundler msg = new StringBundler(4);
2514
2515 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2516
2517 msg.append("parentCategoryId=");
2518 msg.append(parentCategoryId);
2519
2520 msg.append(StringPool.CLOSE_CURLY_BRACE);
2521
2522 throw new NoSuchCategoryException(msg.toString());
2523 }
2524
2525
2533 public AssetCategory fetchByParentCategoryId_Last(long parentCategoryId,
2534 OrderByComparator orderByComparator) throws SystemException {
2535 int count = countByParentCategoryId(parentCategoryId);
2536
2537 List<AssetCategory> list = findByParentCategoryId(parentCategoryId,
2538 count - 1, count, orderByComparator);
2539
2540 if (!list.isEmpty()) {
2541 return list.get(0);
2542 }
2543
2544 return null;
2545 }
2546
2547
2557 public AssetCategory[] findByParentCategoryId_PrevAndNext(long categoryId,
2558 long parentCategoryId, OrderByComparator orderByComparator)
2559 throws NoSuchCategoryException, SystemException {
2560 AssetCategory assetCategory = findByPrimaryKey(categoryId);
2561
2562 Session session = null;
2563
2564 try {
2565 session = openSession();
2566
2567 AssetCategory[] array = new AssetCategoryImpl[3];
2568
2569 array[0] = getByParentCategoryId_PrevAndNext(session,
2570 assetCategory, parentCategoryId, orderByComparator, true);
2571
2572 array[1] = assetCategory;
2573
2574 array[2] = getByParentCategoryId_PrevAndNext(session,
2575 assetCategory, parentCategoryId, orderByComparator, false);
2576
2577 return array;
2578 }
2579 catch (Exception e) {
2580 throw processException(e);
2581 }
2582 finally {
2583 closeSession(session);
2584 }
2585 }
2586
2587 protected AssetCategory getByParentCategoryId_PrevAndNext(Session session,
2588 AssetCategory assetCategory, long parentCategoryId,
2589 OrderByComparator orderByComparator, boolean previous) {
2590 StringBundler query = null;
2591
2592 if (orderByComparator != null) {
2593 query = new StringBundler(6 +
2594 (orderByComparator.getOrderByFields().length * 6));
2595 }
2596 else {
2597 query = new StringBundler(3);
2598 }
2599
2600 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2601
2602 query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2603
2604 if (orderByComparator != null) {
2605 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2606
2607 if (orderByConditionFields.length > 0) {
2608 query.append(WHERE_AND);
2609 }
2610
2611 for (int i = 0; i < orderByConditionFields.length; i++) {
2612 query.append(_ORDER_BY_ENTITY_ALIAS);
2613 query.append(orderByConditionFields[i]);
2614
2615 if ((i + 1) < orderByConditionFields.length) {
2616 if (orderByComparator.isAscending() ^ previous) {
2617 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2618 }
2619 else {
2620 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2621 }
2622 }
2623 else {
2624 if (orderByComparator.isAscending() ^ previous) {
2625 query.append(WHERE_GREATER_THAN);
2626 }
2627 else {
2628 query.append(WHERE_LESSER_THAN);
2629 }
2630 }
2631 }
2632
2633 query.append(ORDER_BY_CLAUSE);
2634
2635 String[] orderByFields = orderByComparator.getOrderByFields();
2636
2637 for (int i = 0; i < orderByFields.length; i++) {
2638 query.append(_ORDER_BY_ENTITY_ALIAS);
2639 query.append(orderByFields[i]);
2640
2641 if ((i + 1) < orderByFields.length) {
2642 if (orderByComparator.isAscending() ^ previous) {
2643 query.append(ORDER_BY_ASC_HAS_NEXT);
2644 }
2645 else {
2646 query.append(ORDER_BY_DESC_HAS_NEXT);
2647 }
2648 }
2649 else {
2650 if (orderByComparator.isAscending() ^ previous) {
2651 query.append(ORDER_BY_ASC);
2652 }
2653 else {
2654 query.append(ORDER_BY_DESC);
2655 }
2656 }
2657 }
2658 }
2659 else {
2660 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2661 }
2662
2663 String sql = query.toString();
2664
2665 Query q = session.createQuery(sql);
2666
2667 q.setFirstResult(0);
2668 q.setMaxResults(2);
2669
2670 QueryPos qPos = QueryPos.getInstance(q);
2671
2672 qPos.add(parentCategoryId);
2673
2674 if (orderByComparator != null) {
2675 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2676
2677 for (Object value : values) {
2678 qPos.add(value);
2679 }
2680 }
2681
2682 List<AssetCategory> list = q.list();
2683
2684 if (list.size() == 2) {
2685 return list.get(1);
2686 }
2687 else {
2688 return null;
2689 }
2690 }
2691
2692
2698 public void removeByParentCategoryId(long parentCategoryId)
2699 throws SystemException {
2700 for (AssetCategory assetCategory : findByParentCategoryId(
2701 parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2702 remove(assetCategory);
2703 }
2704 }
2705
2706
2713 public int countByParentCategoryId(long parentCategoryId)
2714 throws SystemException {
2715 FinderPath finderPath = FINDER_PATH_COUNT_BY_PARENTCATEGORYID;
2716
2717 Object[] finderArgs = new Object[] { parentCategoryId };
2718
2719 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2720 this);
2721
2722 if (count == null) {
2723 StringBundler query = new StringBundler(2);
2724
2725 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2726
2727 query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2728
2729 String sql = query.toString();
2730
2731 Session session = null;
2732
2733 try {
2734 session = openSession();
2735
2736 Query q = session.createQuery(sql);
2737
2738 QueryPos qPos = QueryPos.getInstance(q);
2739
2740 qPos.add(parentCategoryId);
2741
2742 count = (Long)q.uniqueResult();
2743
2744 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2745 }
2746 catch (Exception e) {
2747 FinderCacheUtil.removeResult(finderPath, finderArgs);
2748
2749 throw processException(e);
2750 }
2751 finally {
2752 closeSession(session);
2753 }
2754 }
2755
2756 return count.intValue();
2757 }
2758
2759 private static final String _FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2 =
2760 "assetCategory.parentCategoryId = ?";
2761 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID =
2762 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2763 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2764 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2765 "findByVocabularyId",
2766 new String[] {
2767 Long.class.getName(),
2768
2769 Integer.class.getName(), Integer.class.getName(),
2770 OrderByComparator.class.getName()
2771 });
2772 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID =
2773 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2774 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2775 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2776 "findByVocabularyId", new String[] { Long.class.getName() },
2777 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
2778 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2779 public static final FinderPath FINDER_PATH_COUNT_BY_VOCABULARYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2780 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2781 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVocabularyId",
2782 new String[] { Long.class.getName() });
2783
2784
2791 public List<AssetCategory> findByVocabularyId(long vocabularyId)
2792 throws SystemException {
2793 return findByVocabularyId(vocabularyId, QueryUtil.ALL_POS,
2794 QueryUtil.ALL_POS, null);
2795 }
2796
2797
2810 public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2811 int end) throws SystemException {
2812 return findByVocabularyId(vocabularyId, start, end, null);
2813 }
2814
2815
2829 public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2830 int end, OrderByComparator orderByComparator) throws SystemException {
2831 boolean pagination = true;
2832 FinderPath finderPath = null;
2833 Object[] finderArgs = null;
2834
2835 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2836 (orderByComparator == null)) {
2837 pagination = false;
2838 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID;
2839 finderArgs = new Object[] { vocabularyId };
2840 }
2841 else {
2842 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID;
2843 finderArgs = new Object[] {
2844 vocabularyId,
2845
2846 start, end, orderByComparator
2847 };
2848 }
2849
2850 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
2851 finderArgs, this);
2852
2853 if ((list != null) && !list.isEmpty()) {
2854 for (AssetCategory assetCategory : list) {
2855 if ((vocabularyId != assetCategory.getVocabularyId())) {
2856 list = null;
2857
2858 break;
2859 }
2860 }
2861 }
2862
2863 if (list == null) {
2864 StringBundler query = null;
2865
2866 if (orderByComparator != null) {
2867 query = new StringBundler(3 +
2868 (orderByComparator.getOrderByFields().length * 3));
2869 }
2870 else {
2871 query = new StringBundler(3);
2872 }
2873
2874 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2875
2876 query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
2877
2878 if (orderByComparator != null) {
2879 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2880 orderByComparator);
2881 }
2882 else
2883 if (pagination) {
2884 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2885 }
2886
2887 String sql = query.toString();
2888
2889 Session session = null;
2890
2891 try {
2892 session = openSession();
2893
2894 Query q = session.createQuery(sql);
2895
2896 QueryPos qPos = QueryPos.getInstance(q);
2897
2898 qPos.add(vocabularyId);
2899
2900 if (!pagination) {
2901 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2902 start, end, false);
2903
2904 Collections.sort(list);
2905
2906 list = new UnmodifiableList<AssetCategory>(list);
2907 }
2908 else {
2909 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2910 start, end);
2911 }
2912
2913 cacheResult(list);
2914
2915 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2916 }
2917 catch (Exception e) {
2918 FinderCacheUtil.removeResult(finderPath, finderArgs);
2919
2920 throw processException(e);
2921 }
2922 finally {
2923 closeSession(session);
2924 }
2925 }
2926
2927 return list;
2928 }
2929
2930
2939 public AssetCategory findByVocabularyId_First(long vocabularyId,
2940 OrderByComparator orderByComparator)
2941 throws NoSuchCategoryException, SystemException {
2942 AssetCategory assetCategory = fetchByVocabularyId_First(vocabularyId,
2943 orderByComparator);
2944
2945 if (assetCategory != null) {
2946 return assetCategory;
2947 }
2948
2949 StringBundler msg = new StringBundler(4);
2950
2951 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2952
2953 msg.append("vocabularyId=");
2954 msg.append(vocabularyId);
2955
2956 msg.append(StringPool.CLOSE_CURLY_BRACE);
2957
2958 throw new NoSuchCategoryException(msg.toString());
2959 }
2960
2961
2969 public AssetCategory fetchByVocabularyId_First(long vocabularyId,
2970 OrderByComparator orderByComparator) throws SystemException {
2971 List<AssetCategory> list = findByVocabularyId(vocabularyId, 0, 1,
2972 orderByComparator);
2973
2974 if (!list.isEmpty()) {
2975 return list.get(0);
2976 }
2977
2978 return null;
2979 }
2980
2981
2990 public AssetCategory findByVocabularyId_Last(long vocabularyId,
2991 OrderByComparator orderByComparator)
2992 throws NoSuchCategoryException, SystemException {
2993 AssetCategory assetCategory = fetchByVocabularyId_Last(vocabularyId,
2994 orderByComparator);
2995
2996 if (assetCategory != null) {
2997 return assetCategory;
2998 }
2999
3000 StringBundler msg = new StringBundler(4);
3001
3002 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3003
3004 msg.append("vocabularyId=");
3005 msg.append(vocabularyId);
3006
3007 msg.append(StringPool.CLOSE_CURLY_BRACE);
3008
3009 throw new NoSuchCategoryException(msg.toString());
3010 }
3011
3012
3020 public AssetCategory fetchByVocabularyId_Last(long vocabularyId,
3021 OrderByComparator orderByComparator) throws SystemException {
3022 int count = countByVocabularyId(vocabularyId);
3023
3024 List<AssetCategory> list = findByVocabularyId(vocabularyId, count - 1,
3025 count, orderByComparator);
3026
3027 if (!list.isEmpty()) {
3028 return list.get(0);
3029 }
3030
3031 return null;
3032 }
3033
3034
3044 public AssetCategory[] findByVocabularyId_PrevAndNext(long categoryId,
3045 long vocabularyId, OrderByComparator orderByComparator)
3046 throws NoSuchCategoryException, SystemException {
3047 AssetCategory assetCategory = findByPrimaryKey(categoryId);
3048
3049 Session session = null;
3050
3051 try {
3052 session = openSession();
3053
3054 AssetCategory[] array = new AssetCategoryImpl[3];
3055
3056 array[0] = getByVocabularyId_PrevAndNext(session, assetCategory,
3057 vocabularyId, orderByComparator, true);
3058
3059 array[1] = assetCategory;
3060
3061 array[2] = getByVocabularyId_PrevAndNext(session, assetCategory,
3062 vocabularyId, orderByComparator, false);
3063
3064 return array;
3065 }
3066 catch (Exception e) {
3067 throw processException(e);
3068 }
3069 finally {
3070 closeSession(session);
3071 }
3072 }
3073
3074 protected AssetCategory getByVocabularyId_PrevAndNext(Session session,
3075 AssetCategory assetCategory, long vocabularyId,
3076 OrderByComparator orderByComparator, boolean previous) {
3077 StringBundler query = null;
3078
3079 if (orderByComparator != null) {
3080 query = new StringBundler(6 +
3081 (orderByComparator.getOrderByFields().length * 6));
3082 }
3083 else {
3084 query = new StringBundler(3);
3085 }
3086
3087 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3088
3089 query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3090
3091 if (orderByComparator != null) {
3092 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3093
3094 if (orderByConditionFields.length > 0) {
3095 query.append(WHERE_AND);
3096 }
3097
3098 for (int i = 0; i < orderByConditionFields.length; i++) {
3099 query.append(_ORDER_BY_ENTITY_ALIAS);
3100 query.append(orderByConditionFields[i]);
3101
3102 if ((i + 1) < orderByConditionFields.length) {
3103 if (orderByComparator.isAscending() ^ previous) {
3104 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3105 }
3106 else {
3107 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3108 }
3109 }
3110 else {
3111 if (orderByComparator.isAscending() ^ previous) {
3112 query.append(WHERE_GREATER_THAN);
3113 }
3114 else {
3115 query.append(WHERE_LESSER_THAN);
3116 }
3117 }
3118 }
3119
3120 query.append(ORDER_BY_CLAUSE);
3121
3122 String[] orderByFields = orderByComparator.getOrderByFields();
3123
3124 for (int i = 0; i < orderByFields.length; i++) {
3125 query.append(_ORDER_BY_ENTITY_ALIAS);
3126 query.append(orderByFields[i]);
3127
3128 if ((i + 1) < orderByFields.length) {
3129 if (orderByComparator.isAscending() ^ previous) {
3130 query.append(ORDER_BY_ASC_HAS_NEXT);
3131 }
3132 else {
3133 query.append(ORDER_BY_DESC_HAS_NEXT);
3134 }
3135 }
3136 else {
3137 if (orderByComparator.isAscending() ^ previous) {
3138 query.append(ORDER_BY_ASC);
3139 }
3140 else {
3141 query.append(ORDER_BY_DESC);
3142 }
3143 }
3144 }
3145 }
3146 else {
3147 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3148 }
3149
3150 String sql = query.toString();
3151
3152 Query q = session.createQuery(sql);
3153
3154 q.setFirstResult(0);
3155 q.setMaxResults(2);
3156
3157 QueryPos qPos = QueryPos.getInstance(q);
3158
3159 qPos.add(vocabularyId);
3160
3161 if (orderByComparator != null) {
3162 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3163
3164 for (Object value : values) {
3165 qPos.add(value);
3166 }
3167 }
3168
3169 List<AssetCategory> list = q.list();
3170
3171 if (list.size() == 2) {
3172 return list.get(1);
3173 }
3174 else {
3175 return null;
3176 }
3177 }
3178
3179
3185 public void removeByVocabularyId(long vocabularyId)
3186 throws SystemException {
3187 for (AssetCategory assetCategory : findByVocabularyId(vocabularyId,
3188 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3189 remove(assetCategory);
3190 }
3191 }
3192
3193
3200 public int countByVocabularyId(long vocabularyId) throws SystemException {
3201 FinderPath finderPath = FINDER_PATH_COUNT_BY_VOCABULARYID;
3202
3203 Object[] finderArgs = new Object[] { vocabularyId };
3204
3205 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3206 this);
3207
3208 if (count == null) {
3209 StringBundler query = new StringBundler(2);
3210
3211 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3212
3213 query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3214
3215 String sql = query.toString();
3216
3217 Session session = null;
3218
3219 try {
3220 session = openSession();
3221
3222 Query q = session.createQuery(sql);
3223
3224 QueryPos qPos = QueryPos.getInstance(q);
3225
3226 qPos.add(vocabularyId);
3227
3228 count = (Long)q.uniqueResult();
3229
3230 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3231 }
3232 catch (Exception e) {
3233 FinderCacheUtil.removeResult(finderPath, finderArgs);
3234
3235 throw processException(e);
3236 }
3237 finally {
3238 closeSession(session);
3239 }
3240 }
3241
3242 return count.intValue();
3243 }
3244
3245 private static final String _FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
3246 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3247 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3248 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3249 "findByG_V",
3250 new String[] {
3251 Long.class.getName(), Long.class.getName(),
3252
3253 Integer.class.getName(), Integer.class.getName(),
3254 OrderByComparator.class.getName()
3255 });
3256 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3257 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3258 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3259 "findByG_V",
3260 new String[] { Long.class.getName(), Long.class.getName() },
3261 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
3262 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
3263 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
3264 public static final FinderPath FINDER_PATH_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3265 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3266 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_V",
3267 new String[] { Long.class.getName(), Long.class.getName() });
3268 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3269 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3270 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_V",
3271 new String[] { Long.class.getName(), Long.class.getName() });
3272
3273
3281 public List<AssetCategory> findByG_V(long groupId, long vocabularyId)
3282 throws SystemException {
3283 return findByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3284 QueryUtil.ALL_POS, null);
3285 }
3286
3287
3301 public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3302 int start, int end) throws SystemException {
3303 return findByG_V(groupId, vocabularyId, start, end, null);
3304 }
3305
3306
3321 public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3322 int start, int end, OrderByComparator orderByComparator)
3323 throws SystemException {
3324 boolean pagination = true;
3325 FinderPath finderPath = null;
3326 Object[] finderArgs = null;
3327
3328 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3329 (orderByComparator == null)) {
3330 pagination = false;
3331 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V;
3332 finderArgs = new Object[] { groupId, vocabularyId };
3333 }
3334 else {
3335 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V;
3336 finderArgs = new Object[] {
3337 groupId, vocabularyId,
3338
3339 start, end, orderByComparator
3340 };
3341 }
3342
3343 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
3344 finderArgs, this);
3345
3346 if ((list != null) && !list.isEmpty()) {
3347 for (AssetCategory assetCategory : list) {
3348 if ((groupId != assetCategory.getGroupId()) ||
3349 (vocabularyId != assetCategory.getVocabularyId())) {
3350 list = null;
3351
3352 break;
3353 }
3354 }
3355 }
3356
3357 if (list == null) {
3358 StringBundler query = null;
3359
3360 if (orderByComparator != null) {
3361 query = new StringBundler(4 +
3362 (orderByComparator.getOrderByFields().length * 3));
3363 }
3364 else {
3365 query = new StringBundler(4);
3366 }
3367
3368 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3369
3370 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3371
3372 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3373
3374 if (orderByComparator != null) {
3375 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3376 orderByComparator);
3377 }
3378 else
3379 if (pagination) {
3380 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3381 }
3382
3383 String sql = query.toString();
3384
3385 Session session = null;
3386
3387 try {
3388 session = openSession();
3389
3390 Query q = session.createQuery(sql);
3391
3392 QueryPos qPos = QueryPos.getInstance(q);
3393
3394 qPos.add(groupId);
3395
3396 qPos.add(vocabularyId);
3397
3398 if (!pagination) {
3399 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3400 start, end, false);
3401
3402 Collections.sort(list);
3403
3404 list = new UnmodifiableList<AssetCategory>(list);
3405 }
3406 else {
3407 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3408 start, end);
3409 }
3410
3411 cacheResult(list);
3412
3413 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3414 }
3415 catch (Exception e) {
3416 FinderCacheUtil.removeResult(finderPath, finderArgs);
3417
3418 throw processException(e);
3419 }
3420 finally {
3421 closeSession(session);
3422 }
3423 }
3424
3425 return list;
3426 }
3427
3428
3438 public AssetCategory findByG_V_First(long groupId, long vocabularyId,
3439 OrderByComparator orderByComparator)
3440 throws NoSuchCategoryException, SystemException {
3441 AssetCategory assetCategory = fetchByG_V_First(groupId, vocabularyId,
3442 orderByComparator);
3443
3444 if (assetCategory != null) {
3445 return assetCategory;
3446 }
3447
3448 StringBundler msg = new StringBundler(6);
3449
3450 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3451
3452 msg.append("groupId=");
3453 msg.append(groupId);
3454
3455 msg.append(", vocabularyId=");
3456 msg.append(vocabularyId);
3457
3458 msg.append(StringPool.CLOSE_CURLY_BRACE);
3459
3460 throw new NoSuchCategoryException(msg.toString());
3461 }
3462
3463
3472 public AssetCategory fetchByG_V_First(long groupId, long vocabularyId,
3473 OrderByComparator orderByComparator) throws SystemException {
3474 List<AssetCategory> list = findByG_V(groupId, vocabularyId, 0, 1,
3475 orderByComparator);
3476
3477 if (!list.isEmpty()) {
3478 return list.get(0);
3479 }
3480
3481 return null;
3482 }
3483
3484
3494 public AssetCategory findByG_V_Last(long groupId, long vocabularyId,
3495 OrderByComparator orderByComparator)
3496 throws NoSuchCategoryException, SystemException {
3497 AssetCategory assetCategory = fetchByG_V_Last(groupId, vocabularyId,
3498 orderByComparator);
3499
3500 if (assetCategory != null) {
3501 return assetCategory;
3502 }
3503
3504 StringBundler msg = new StringBundler(6);
3505
3506 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3507
3508 msg.append("groupId=");
3509 msg.append(groupId);
3510
3511 msg.append(", vocabularyId=");
3512 msg.append(vocabularyId);
3513
3514 msg.append(StringPool.CLOSE_CURLY_BRACE);
3515
3516 throw new NoSuchCategoryException(msg.toString());
3517 }
3518
3519
3528 public AssetCategory fetchByG_V_Last(long groupId, long vocabularyId,
3529 OrderByComparator orderByComparator) throws SystemException {
3530 int count = countByG_V(groupId, vocabularyId);
3531
3532 List<AssetCategory> list = findByG_V(groupId, vocabularyId, count - 1,
3533 count, orderByComparator);
3534
3535 if (!list.isEmpty()) {
3536 return list.get(0);
3537 }
3538
3539 return null;
3540 }
3541
3542
3553 public AssetCategory[] findByG_V_PrevAndNext(long categoryId, long groupId,
3554 long vocabularyId, OrderByComparator orderByComparator)
3555 throws NoSuchCategoryException, SystemException {
3556 AssetCategory assetCategory = findByPrimaryKey(categoryId);
3557
3558 Session session = null;
3559
3560 try {
3561 session = openSession();
3562
3563 AssetCategory[] array = new AssetCategoryImpl[3];
3564
3565 array[0] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3566 vocabularyId, orderByComparator, true);
3567
3568 array[1] = assetCategory;
3569
3570 array[2] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3571 vocabularyId, orderByComparator, false);
3572
3573 return array;
3574 }
3575 catch (Exception e) {
3576 throw processException(e);
3577 }
3578 finally {
3579 closeSession(session);
3580 }
3581 }
3582
3583 protected AssetCategory getByG_V_PrevAndNext(Session session,
3584 AssetCategory assetCategory, long groupId, long vocabularyId,
3585 OrderByComparator orderByComparator, boolean previous) {
3586 StringBundler query = null;
3587
3588 if (orderByComparator != null) {
3589 query = new StringBundler(6 +
3590 (orderByComparator.getOrderByFields().length * 6));
3591 }
3592 else {
3593 query = new StringBundler(3);
3594 }
3595
3596 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3597
3598 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3599
3600 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3601
3602 if (orderByComparator != null) {
3603 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3604
3605 if (orderByConditionFields.length > 0) {
3606 query.append(WHERE_AND);
3607 }
3608
3609 for (int i = 0; i < orderByConditionFields.length; i++) {
3610 query.append(_ORDER_BY_ENTITY_ALIAS);
3611 query.append(orderByConditionFields[i]);
3612
3613 if ((i + 1) < orderByConditionFields.length) {
3614 if (orderByComparator.isAscending() ^ previous) {
3615 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3616 }
3617 else {
3618 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3619 }
3620 }
3621 else {
3622 if (orderByComparator.isAscending() ^ previous) {
3623 query.append(WHERE_GREATER_THAN);
3624 }
3625 else {
3626 query.append(WHERE_LESSER_THAN);
3627 }
3628 }
3629 }
3630
3631 query.append(ORDER_BY_CLAUSE);
3632
3633 String[] orderByFields = orderByComparator.getOrderByFields();
3634
3635 for (int i = 0; i < orderByFields.length; i++) {
3636 query.append(_ORDER_BY_ENTITY_ALIAS);
3637 query.append(orderByFields[i]);
3638
3639 if ((i + 1) < orderByFields.length) {
3640 if (orderByComparator.isAscending() ^ previous) {
3641 query.append(ORDER_BY_ASC_HAS_NEXT);
3642 }
3643 else {
3644 query.append(ORDER_BY_DESC_HAS_NEXT);
3645 }
3646 }
3647 else {
3648 if (orderByComparator.isAscending() ^ previous) {
3649 query.append(ORDER_BY_ASC);
3650 }
3651 else {
3652 query.append(ORDER_BY_DESC);
3653 }
3654 }
3655 }
3656 }
3657 else {
3658 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3659 }
3660
3661 String sql = query.toString();
3662
3663 Query q = session.createQuery(sql);
3664
3665 q.setFirstResult(0);
3666 q.setMaxResults(2);
3667
3668 QueryPos qPos = QueryPos.getInstance(q);
3669
3670 qPos.add(groupId);
3671
3672 qPos.add(vocabularyId);
3673
3674 if (orderByComparator != null) {
3675 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3676
3677 for (Object value : values) {
3678 qPos.add(value);
3679 }
3680 }
3681
3682 List<AssetCategory> list = q.list();
3683
3684 if (list.size() == 2) {
3685 return list.get(1);
3686 }
3687 else {
3688 return null;
3689 }
3690 }
3691
3692
3700 public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId)
3701 throws SystemException {
3702 return filterFindByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3703 QueryUtil.ALL_POS, null);
3704 }
3705
3706
3720 public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3721 int start, int end) throws SystemException {
3722 return filterFindByG_V(groupId, vocabularyId, start, end, null);
3723 }
3724
3725
3740 public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3741 int start, int end, OrderByComparator orderByComparator)
3742 throws SystemException {
3743 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3744 return findByG_V(groupId, vocabularyId, start, end,
3745 orderByComparator);
3746 }
3747
3748 StringBundler query = null;
3749
3750 if (orderByComparator != null) {
3751 query = new StringBundler(4 +
3752 (orderByComparator.getOrderByFields().length * 3));
3753 }
3754 else {
3755 query = new StringBundler(4);
3756 }
3757
3758 if (getDB().isSupportsInlineDistinct()) {
3759 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3760 }
3761 else {
3762 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3763 }
3764
3765 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3766
3767 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3768
3769 if (!getDB().isSupportsInlineDistinct()) {
3770 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3771 }
3772
3773 if (orderByComparator != null) {
3774 if (getDB().isSupportsInlineDistinct()) {
3775 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3776 orderByComparator);
3777 }
3778 else {
3779 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3780 orderByComparator);
3781 }
3782 }
3783 else {
3784 if (getDB().isSupportsInlineDistinct()) {
3785 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3786 }
3787 else {
3788 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
3789 }
3790 }
3791
3792 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3793 AssetCategory.class.getName(),
3794 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3795
3796 Session session = null;
3797
3798 try {
3799 session = openSession();
3800
3801 SQLQuery q = session.createSQLQuery(sql);
3802
3803 if (getDB().isSupportsInlineDistinct()) {
3804 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
3805 }
3806 else {
3807 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
3808 }
3809
3810 QueryPos qPos = QueryPos.getInstance(q);
3811
3812 qPos.add(groupId);
3813
3814 qPos.add(vocabularyId);
3815
3816 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
3817 end);
3818 }
3819 catch (Exception e) {
3820 throw processException(e);
3821 }
3822 finally {
3823 closeSession(session);
3824 }
3825 }
3826
3827
3838 public AssetCategory[] filterFindByG_V_PrevAndNext(long categoryId,
3839 long groupId, long vocabularyId, OrderByComparator orderByComparator)
3840 throws NoSuchCategoryException, SystemException {
3841 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3842 return findByG_V_PrevAndNext(categoryId, groupId, vocabularyId,
3843 orderByComparator);
3844 }
3845
3846 AssetCategory assetCategory = findByPrimaryKey(categoryId);
3847
3848 Session session = null;
3849
3850 try {
3851 session = openSession();
3852
3853 AssetCategory[] array = new AssetCategoryImpl[3];
3854
3855 array[0] = filterGetByG_V_PrevAndNext(session, assetCategory,
3856 groupId, vocabularyId, orderByComparator, true);
3857
3858 array[1] = assetCategory;
3859
3860 array[2] = filterGetByG_V_PrevAndNext(session, assetCategory,
3861 groupId, vocabularyId, orderByComparator, false);
3862
3863 return array;
3864 }
3865 catch (Exception e) {
3866 throw processException(e);
3867 }
3868 finally {
3869 closeSession(session);
3870 }
3871 }
3872
3873 protected AssetCategory filterGetByG_V_PrevAndNext(Session session,
3874 AssetCategory assetCategory, long groupId, long vocabularyId,
3875 OrderByComparator orderByComparator, boolean previous) {
3876 StringBundler query = null;
3877
3878 if (orderByComparator != null) {
3879 query = new StringBundler(6 +
3880 (orderByComparator.getOrderByFields().length * 6));
3881 }
3882 else {
3883 query = new StringBundler(3);
3884 }
3885
3886 if (getDB().isSupportsInlineDistinct()) {
3887 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3888 }
3889 else {
3890 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3891 }
3892
3893 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3894
3895 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3896
3897 if (!getDB().isSupportsInlineDistinct()) {
3898 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3899 }
3900
3901 if (orderByComparator != null) {
3902 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3903
3904 if (orderByConditionFields.length > 0) {
3905 query.append(WHERE_AND);
3906 }
3907
3908 for (int i = 0; i < orderByConditionFields.length; i++) {
3909 if (getDB().isSupportsInlineDistinct()) {
3910 query.append(_ORDER_BY_ENTITY_ALIAS);
3911 }
3912 else {
3913 query.append(_ORDER_BY_ENTITY_TABLE);
3914 }
3915
3916 query.append(orderByConditionFields[i]);
3917
3918 if ((i + 1) < orderByConditionFields.length) {
3919 if (orderByComparator.isAscending() ^ previous) {
3920 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3921 }
3922 else {
3923 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3924 }
3925 }
3926 else {
3927 if (orderByComparator.isAscending() ^ previous) {
3928 query.append(WHERE_GREATER_THAN);
3929 }
3930 else {
3931 query.append(WHERE_LESSER_THAN);
3932 }
3933 }
3934 }
3935
3936 query.append(ORDER_BY_CLAUSE);
3937
3938 String[] orderByFields = orderByComparator.getOrderByFields();
3939
3940 for (int i = 0; i < orderByFields.length; i++) {
3941 if (getDB().isSupportsInlineDistinct()) {
3942 query.append(_ORDER_BY_ENTITY_ALIAS);
3943 }
3944 else {
3945 query.append(_ORDER_BY_ENTITY_TABLE);
3946 }
3947
3948 query.append(orderByFields[i]);
3949
3950 if ((i + 1) < orderByFields.length) {
3951 if (orderByComparator.isAscending() ^ previous) {
3952 query.append(ORDER_BY_ASC_HAS_NEXT);
3953 }
3954 else {
3955 query.append(ORDER_BY_DESC_HAS_NEXT);
3956 }
3957 }
3958 else {
3959 if (orderByComparator.isAscending() ^ previous) {
3960 query.append(ORDER_BY_ASC);
3961 }
3962 else {
3963 query.append(ORDER_BY_DESC);
3964 }
3965 }
3966 }
3967 }
3968 else {
3969 if (getDB().isSupportsInlineDistinct()) {
3970 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3971 }
3972 else {
3973 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
3974 }
3975 }
3976
3977 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3978 AssetCategory.class.getName(),
3979 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3980
3981 SQLQuery q = session.createSQLQuery(sql);
3982
3983 q.setFirstResult(0);
3984 q.setMaxResults(2);
3985
3986 if (getDB().isSupportsInlineDistinct()) {
3987 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
3988 }
3989 else {
3990 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
3991 }
3992
3993 QueryPos qPos = QueryPos.getInstance(q);
3994
3995 qPos.add(groupId);
3996
3997 qPos.add(vocabularyId);
3998
3999 if (orderByComparator != null) {
4000 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
4001
4002 for (Object value : values) {
4003 qPos.add(value);
4004 }
4005 }
4006
4007 List<AssetCategory> list = q.list();
4008
4009 if (list.size() == 2) {
4010 return list.get(1);
4011 }
4012 else {
4013 return null;
4014 }
4015 }
4016
4017
4025 public List<AssetCategory> filterFindByG_V(long groupId,
4026 long[] vocabularyIds) throws SystemException {
4027 return filterFindByG_V(groupId, vocabularyIds, QueryUtil.ALL_POS,
4028 QueryUtil.ALL_POS, null);
4029 }
4030
4031
4045 public List<AssetCategory> filterFindByG_V(long groupId,
4046 long[] vocabularyIds, int start, int end) throws SystemException {
4047 return filterFindByG_V(groupId, vocabularyIds, start, end, null);
4048 }
4049
4050
4065 public List<AssetCategory> filterFindByG_V(long groupId,
4066 long[] vocabularyIds, int start, int end,
4067 OrderByComparator orderByComparator) throws SystemException {
4068 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4069 return findByG_V(groupId, vocabularyIds, start, end,
4070 orderByComparator);
4071 }
4072
4073 StringBundler query = new StringBundler();
4074
4075 if (getDB().isSupportsInlineDistinct()) {
4076 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
4077 }
4078 else {
4079 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4080 }
4081
4082 boolean conjunctionable = false;
4083
4084 if (conjunctionable) {
4085 query.append(WHERE_AND);
4086 }
4087
4088 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4089
4090 conjunctionable = true;
4091
4092 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4093 if (conjunctionable) {
4094 query.append(WHERE_AND);
4095 }
4096
4097 query.append(StringPool.OPEN_PARENTHESIS);
4098
4099 for (int i = 0; i < vocabularyIds.length; i++) {
4100 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4101
4102 if ((i + 1) < vocabularyIds.length) {
4103 query.append(WHERE_OR);
4104 }
4105 }
4106
4107 query.append(StringPool.CLOSE_PARENTHESIS);
4108
4109 conjunctionable = true;
4110 }
4111
4112 if (!getDB().isSupportsInlineDistinct()) {
4113 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4114 }
4115
4116 if (orderByComparator != null) {
4117 if (getDB().isSupportsInlineDistinct()) {
4118 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4119 orderByComparator);
4120 }
4121 else {
4122 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4123 orderByComparator);
4124 }
4125 }
4126 else {
4127 if (getDB().isSupportsInlineDistinct()) {
4128 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4129 }
4130 else {
4131 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
4132 }
4133 }
4134
4135 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4136 AssetCategory.class.getName(),
4137 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4138
4139 Session session = null;
4140
4141 try {
4142 session = openSession();
4143
4144 SQLQuery q = session.createSQLQuery(sql);
4145
4146 if (getDB().isSupportsInlineDistinct()) {
4147 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
4148 }
4149 else {
4150 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
4151 }
4152
4153 QueryPos qPos = QueryPos.getInstance(q);
4154
4155 qPos.add(groupId);
4156
4157 if (vocabularyIds != null) {
4158 qPos.add(vocabularyIds);
4159 }
4160
4161 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
4162 end);
4163 }
4164 catch (Exception e) {
4165 throw processException(e);
4166 }
4167 finally {
4168 closeSession(session);
4169 }
4170 }
4171
4172
4184 public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds)
4185 throws SystemException {
4186 return findByG_V(groupId, vocabularyIds, QueryUtil.ALL_POS,
4187 QueryUtil.ALL_POS, null);
4188 }
4189
4190
4204 public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4205 int start, int end) throws SystemException {
4206 return findByG_V(groupId, vocabularyIds, start, end, null);
4207 }
4208
4209
4224 public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4225 int start, int end, OrderByComparator orderByComparator)
4226 throws SystemException {
4227 if ((vocabularyIds != null) && (vocabularyIds.length == 1)) {
4228 return findByG_V(groupId, vocabularyIds[0], start, end,
4229 orderByComparator);
4230 }
4231
4232 boolean pagination = true;
4233 Object[] finderArgs = null;
4234
4235 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4236 (orderByComparator == null)) {
4237 pagination = false;
4238 finderArgs = new Object[] { groupId, StringUtil.merge(vocabularyIds) };
4239 }
4240 else {
4241 finderArgs = new Object[] {
4242 groupId, StringUtil.merge(vocabularyIds),
4243
4244 start, end, orderByComparator
4245 };
4246 }
4247
4248 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4249 finderArgs, this);
4250
4251 if ((list != null) && !list.isEmpty()) {
4252 for (AssetCategory assetCategory : list) {
4253 if ((groupId != assetCategory.getGroupId()) ||
4254 !ArrayUtil.contains(vocabularyIds,
4255 assetCategory.getVocabularyId())) {
4256 list = null;
4257
4258 break;
4259 }
4260 }
4261 }
4262
4263 if (list == null) {
4264 StringBundler query = new StringBundler();
4265
4266 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4267
4268 boolean conjunctionable = false;
4269
4270 if (conjunctionable) {
4271 query.append(WHERE_AND);
4272 }
4273
4274 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4275
4276 conjunctionable = true;
4277
4278 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4279 if (conjunctionable) {
4280 query.append(WHERE_AND);
4281 }
4282
4283 query.append(StringPool.OPEN_PARENTHESIS);
4284
4285 for (int i = 0; i < vocabularyIds.length; i++) {
4286 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4287
4288 if ((i + 1) < vocabularyIds.length) {
4289 query.append(WHERE_OR);
4290 }
4291 }
4292
4293 query.append(StringPool.CLOSE_PARENTHESIS);
4294
4295 conjunctionable = true;
4296 }
4297
4298 if (orderByComparator != null) {
4299 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4300 orderByComparator);
4301 }
4302 else
4303 if (pagination) {
4304 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4305 }
4306
4307 String sql = query.toString();
4308
4309 Session session = null;
4310
4311 try {
4312 session = openSession();
4313
4314 Query q = session.createQuery(sql);
4315
4316 QueryPos qPos = QueryPos.getInstance(q);
4317
4318 qPos.add(groupId);
4319
4320 if (vocabularyIds != null) {
4321 qPos.add(vocabularyIds);
4322 }
4323
4324 if (!pagination) {
4325 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4326 start, end, false);
4327
4328 Collections.sort(list);
4329
4330 list = new UnmodifiableList<AssetCategory>(list);
4331 }
4332 else {
4333 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4334 start, end);
4335 }
4336
4337 cacheResult(list);
4338
4339 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4340 finderArgs, list);
4341 }
4342 catch (Exception e) {
4343 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4344 finderArgs);
4345
4346 throw processException(e);
4347 }
4348 finally {
4349 closeSession(session);
4350 }
4351 }
4352
4353 return list;
4354 }
4355
4356
4363 public void removeByG_V(long groupId, long vocabularyId)
4364 throws SystemException {
4365 for (AssetCategory assetCategory : findByG_V(groupId, vocabularyId,
4366 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4367 remove(assetCategory);
4368 }
4369 }
4370
4371
4379 public int countByG_V(long groupId, long vocabularyId)
4380 throws SystemException {
4381 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_V;
4382
4383 Object[] finderArgs = new Object[] { groupId, vocabularyId };
4384
4385 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4386 this);
4387
4388 if (count == null) {
4389 StringBundler query = new StringBundler(3);
4390
4391 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4392
4393 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4394
4395 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4396
4397 String sql = query.toString();
4398
4399 Session session = null;
4400
4401 try {
4402 session = openSession();
4403
4404 Query q = session.createQuery(sql);
4405
4406 QueryPos qPos = QueryPos.getInstance(q);
4407
4408 qPos.add(groupId);
4409
4410 qPos.add(vocabularyId);
4411
4412 count = (Long)q.uniqueResult();
4413
4414 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4415 }
4416 catch (Exception e) {
4417 FinderCacheUtil.removeResult(finderPath, finderArgs);
4418
4419 throw processException(e);
4420 }
4421 finally {
4422 closeSession(session);
4423 }
4424 }
4425
4426 return count.intValue();
4427 }
4428
4429
4437 public int countByG_V(long groupId, long[] vocabularyIds)
4438 throws SystemException {
4439 Object[] finderArgs = new Object[] {
4440 groupId, StringUtil.merge(vocabularyIds)
4441 };
4442
4443 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4444 finderArgs, this);
4445
4446 if (count == null) {
4447 StringBundler query = new StringBundler();
4448
4449 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4450
4451 boolean conjunctionable = false;
4452
4453 if (conjunctionable) {
4454 query.append(WHERE_AND);
4455 }
4456
4457 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4458
4459 conjunctionable = true;
4460
4461 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4462 if (conjunctionable) {
4463 query.append(WHERE_AND);
4464 }
4465
4466 query.append(StringPool.OPEN_PARENTHESIS);
4467
4468 for (int i = 0; i < vocabularyIds.length; i++) {
4469 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4470
4471 if ((i + 1) < vocabularyIds.length) {
4472 query.append(WHERE_OR);
4473 }
4474 }
4475
4476 query.append(StringPool.CLOSE_PARENTHESIS);
4477
4478 conjunctionable = true;
4479 }
4480
4481 String sql = query.toString();
4482
4483 Session session = null;
4484
4485 try {
4486 session = openSession();
4487
4488 Query q = session.createQuery(sql);
4489
4490 QueryPos qPos = QueryPos.getInstance(q);
4491
4492 qPos.add(groupId);
4493
4494 if (vocabularyIds != null) {
4495 qPos.add(vocabularyIds);
4496 }
4497
4498 count = (Long)q.uniqueResult();
4499
4500 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4501 finderArgs, count);
4502 }
4503 catch (Exception e) {
4504 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4505 finderArgs);
4506
4507 throw processException(e);
4508 }
4509 finally {
4510 closeSession(session);
4511 }
4512 }
4513
4514 return count.intValue();
4515 }
4516
4517
4525 public int filterCountByG_V(long groupId, long vocabularyId)
4526 throws SystemException {
4527 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4528 return countByG_V(groupId, vocabularyId);
4529 }
4530
4531 StringBundler query = new StringBundler(3);
4532
4533 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4534
4535 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4536
4537 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4538
4539 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4540 AssetCategory.class.getName(),
4541 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4542
4543 Session session = null;
4544
4545 try {
4546 session = openSession();
4547
4548 SQLQuery q = session.createSQLQuery(sql);
4549
4550 q.addScalar(COUNT_COLUMN_NAME,
4551 com.liferay.portal.kernel.dao.orm.Type.LONG);
4552
4553 QueryPos qPos = QueryPos.getInstance(q);
4554
4555 qPos.add(groupId);
4556
4557 qPos.add(vocabularyId);
4558
4559 Long count = (Long)q.uniqueResult();
4560
4561 return count.intValue();
4562 }
4563 catch (Exception e) {
4564 throw processException(e);
4565 }
4566 finally {
4567 closeSession(session);
4568 }
4569 }
4570
4571
4579 public int filterCountByG_V(long groupId, long[] vocabularyIds)
4580 throws SystemException {
4581 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4582 return countByG_V(groupId, vocabularyIds);
4583 }
4584
4585 StringBundler query = new StringBundler();
4586
4587 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4588
4589 boolean conjunctionable = false;
4590
4591 if (conjunctionable) {
4592 query.append(WHERE_AND);
4593 }
4594
4595 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4596
4597 conjunctionable = true;
4598
4599 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4600 if (conjunctionable) {
4601 query.append(WHERE_AND);
4602 }
4603
4604 query.append(StringPool.OPEN_PARENTHESIS);
4605
4606 for (int i = 0; i < vocabularyIds.length; i++) {
4607 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4608
4609 if ((i + 1) < vocabularyIds.length) {
4610 query.append(WHERE_OR);
4611 }
4612 }
4613
4614 query.append(StringPool.CLOSE_PARENTHESIS);
4615
4616 conjunctionable = true;
4617 }
4618
4619 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4620 AssetCategory.class.getName(),
4621 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4622
4623 Session session = null;
4624
4625 try {
4626 session = openSession();
4627
4628 SQLQuery q = session.createSQLQuery(sql);
4629
4630 q.addScalar(COUNT_COLUMN_NAME,
4631 com.liferay.portal.kernel.dao.orm.Type.LONG);
4632
4633 QueryPos qPos = QueryPos.getInstance(q);
4634
4635 qPos.add(groupId);
4636
4637 if (vocabularyIds != null) {
4638 qPos.add(vocabularyIds);
4639 }
4640
4641 Long count = (Long)q.uniqueResult();
4642
4643 return count.intValue();
4644 }
4645 catch (Exception e) {
4646 throw processException(e);
4647 }
4648 finally {
4649 closeSession(session);
4650 }
4651 }
4652
4653 private static final String _FINDER_COLUMN_G_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
4654 private static final String _FINDER_COLUMN_G_V_GROUPID_5 = "(" +
4655 removeConjunction(_FINDER_COLUMN_G_V_GROUPID_2) + ")";
4656 private static final String _FINDER_COLUMN_G_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
4657 private static final String _FINDER_COLUMN_G_V_VOCABULARYID_5 = "(" +
4658 removeConjunction(_FINDER_COLUMN_G_V_VOCABULARYID_2) + ")";
4659 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4660 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4661 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4662 "findByP_N",
4663 new String[] {
4664 Long.class.getName(), String.class.getName(),
4665
4666 Integer.class.getName(), Integer.class.getName(),
4667 OrderByComparator.class.getName()
4668 });
4669 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4670 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4671 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4672 "findByP_N",
4673 new String[] { Long.class.getName(), String.class.getName() },
4674 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4675 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
4676 public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4677 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4678 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
4679 new String[] { Long.class.getName(), String.class.getName() });
4680
4681
4689 public List<AssetCategory> findByP_N(long parentCategoryId, String name)
4690 throws SystemException {
4691 return findByP_N(parentCategoryId, name, QueryUtil.ALL_POS,
4692 QueryUtil.ALL_POS, null);
4693 }
4694
4695
4709 public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4710 int start, int end) throws SystemException {
4711 return findByP_N(parentCategoryId, name, start, end, null);
4712 }
4713
4714
4729 public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4730 int start, int end, OrderByComparator orderByComparator)
4731 throws SystemException {
4732 boolean pagination = true;
4733 FinderPath finderPath = null;
4734 Object[] finderArgs = null;
4735
4736 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4737 (orderByComparator == null)) {
4738 pagination = false;
4739 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
4740 finderArgs = new Object[] { parentCategoryId, name };
4741 }
4742 else {
4743 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
4744 finderArgs = new Object[] {
4745 parentCategoryId, name,
4746
4747 start, end, orderByComparator
4748 };
4749 }
4750
4751 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
4752 finderArgs, this);
4753
4754 if ((list != null) && !list.isEmpty()) {
4755 for (AssetCategory assetCategory : list) {
4756 if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
4757 !Validator.equals(name, assetCategory.getName())) {
4758 list = null;
4759
4760 break;
4761 }
4762 }
4763 }
4764
4765 if (list == null) {
4766 StringBundler query = null;
4767
4768 if (orderByComparator != null) {
4769 query = new StringBundler(4 +
4770 (orderByComparator.getOrderByFields().length * 3));
4771 }
4772 else {
4773 query = new StringBundler(4);
4774 }
4775
4776 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4777
4778 query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4779
4780 boolean bindName = false;
4781
4782 if (name == null) {
4783 query.append(_FINDER_COLUMN_P_N_NAME_1);
4784 }
4785 else if (name.equals(StringPool.BLANK)) {
4786 query.append(_FINDER_COLUMN_P_N_NAME_3);
4787 }
4788 else {
4789 bindName = true;
4790
4791 query.append(_FINDER_COLUMN_P_N_NAME_2);
4792 }
4793
4794 if (orderByComparator != null) {
4795 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4796 orderByComparator);
4797 }
4798 else
4799 if (pagination) {
4800 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4801 }
4802
4803 String sql = query.toString();
4804
4805 Session session = null;
4806
4807 try {
4808 session = openSession();
4809
4810 Query q = session.createQuery(sql);
4811
4812 QueryPos qPos = QueryPos.getInstance(q);
4813
4814 qPos.add(parentCategoryId);
4815
4816 if (bindName) {
4817 qPos.add(name);
4818 }
4819
4820 if (!pagination) {
4821 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4822 start, end, false);
4823
4824 Collections.sort(list);
4825
4826 list = new UnmodifiableList<AssetCategory>(list);
4827 }
4828 else {
4829 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4830 start, end);
4831 }
4832
4833 cacheResult(list);
4834
4835 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4836 }
4837 catch (Exception e) {
4838 FinderCacheUtil.removeResult(finderPath, finderArgs);
4839
4840 throw processException(e);
4841 }
4842 finally {
4843 closeSession(session);
4844 }
4845 }
4846
4847 return list;
4848 }
4849
4850
4860 public AssetCategory findByP_N_First(long parentCategoryId, String name,
4861 OrderByComparator orderByComparator)
4862 throws NoSuchCategoryException, SystemException {
4863 AssetCategory assetCategory = fetchByP_N_First(parentCategoryId, name,
4864 orderByComparator);
4865
4866 if (assetCategory != null) {
4867 return assetCategory;
4868 }
4869
4870 StringBundler msg = new StringBundler(6);
4871
4872 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4873
4874 msg.append("parentCategoryId=");
4875 msg.append(parentCategoryId);
4876
4877 msg.append(", name=");
4878 msg.append(name);
4879
4880 msg.append(StringPool.CLOSE_CURLY_BRACE);
4881
4882 throw new NoSuchCategoryException(msg.toString());
4883 }
4884
4885
4894 public AssetCategory fetchByP_N_First(long parentCategoryId, String name,
4895 OrderByComparator orderByComparator) throws SystemException {
4896 List<AssetCategory> list = findByP_N(parentCategoryId, name, 0, 1,
4897 orderByComparator);
4898
4899 if (!list.isEmpty()) {
4900 return list.get(0);
4901 }
4902
4903 return null;
4904 }
4905
4906
4916 public AssetCategory findByP_N_Last(long parentCategoryId, String name,
4917 OrderByComparator orderByComparator)
4918 throws NoSuchCategoryException, SystemException {
4919 AssetCategory assetCategory = fetchByP_N_Last(parentCategoryId, name,
4920 orderByComparator);
4921
4922 if (assetCategory != null) {
4923 return assetCategory;
4924 }
4925
4926 StringBundler msg = new StringBundler(6);
4927
4928 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4929
4930 msg.append("parentCategoryId=");
4931 msg.append(parentCategoryId);
4932
4933 msg.append(", name=");
4934 msg.append(name);
4935
4936 msg.append(StringPool.CLOSE_CURLY_BRACE);
4937
4938 throw new NoSuchCategoryException(msg.toString());
4939 }
4940
4941
4950 public AssetCategory fetchByP_N_Last(long parentCategoryId, String name,
4951 OrderByComparator orderByComparator) throws SystemException {
4952 int count = countByP_N(parentCategoryId, name);
4953
4954 List<AssetCategory> list = findByP_N(parentCategoryId, name, count - 1,
4955 count, orderByComparator);
4956
4957 if (!list.isEmpty()) {
4958 return list.get(0);
4959 }
4960
4961 return null;
4962 }
4963
4964
4975 public AssetCategory[] findByP_N_PrevAndNext(long categoryId,
4976 long parentCategoryId, String name, OrderByComparator orderByComparator)
4977 throws NoSuchCategoryException, SystemException {
4978 AssetCategory assetCategory = findByPrimaryKey(categoryId);
4979
4980 Session session = null;
4981
4982 try {
4983 session = openSession();
4984
4985 AssetCategory[] array = new AssetCategoryImpl[3];
4986
4987 array[0] = getByP_N_PrevAndNext(session, assetCategory,
4988 parentCategoryId, name, orderByComparator, true);
4989
4990 array[1] = assetCategory;
4991
4992 array[2] = getByP_N_PrevAndNext(session, assetCategory,
4993 parentCategoryId, name, orderByComparator, false);
4994
4995 return array;
4996 }
4997 catch (Exception e) {
4998 throw processException(e);
4999 }
5000 finally {
5001 closeSession(session);
5002 }
5003 }
5004
5005 protected AssetCategory getByP_N_PrevAndNext(Session session,
5006 AssetCategory assetCategory, long parentCategoryId, String name,
5007 OrderByComparator orderByComparator, boolean previous) {
5008 StringBundler query = null;
5009
5010 if (orderByComparator != null) {
5011 query = new StringBundler(6 +
5012 (orderByComparator.getOrderByFields().length * 6));
5013 }
5014 else {
5015 query = new StringBundler(3);
5016 }
5017
5018 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5019
5020 query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
5021
5022 boolean bindName = false;
5023
5024 if (name == null) {
5025 query.append(_FINDER_COLUMN_P_N_NAME_1);
5026 }
5027 else if (name.equals(StringPool.BLANK)) {
5028 query.append(_FINDER_COLUMN_P_N_NAME_3);
5029 }
5030 else {
5031 bindName = true;
5032
5033 query.append(_FINDER_COLUMN_P_N_NAME_2);
5034 }
5035
5036 if (orderByComparator != null) {
5037 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5038
5039 if (orderByConditionFields.length > 0) {
5040 query.append(WHERE_AND);
5041 }
5042
5043 for (int i = 0; i < orderByConditionFields.length; i++) {
5044 query.append(_ORDER_BY_ENTITY_ALIAS);
5045 query.append(orderByConditionFields[i]);
5046
5047 if ((i + 1) < orderByConditionFields.length) {
5048 if (orderByComparator.isAscending() ^ previous) {
5049 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5050 }
5051 else {
5052 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5053 }
5054 }
5055 else {
5056 if (orderByComparator.isAscending() ^ previous) {
5057 query.append(WHERE_GREATER_THAN);
5058 }
5059 else {
5060 query.append(WHERE_LESSER_THAN);
5061 }
5062 }
5063 }
5064
5065 query.append(ORDER_BY_CLAUSE);
5066
5067 String[] orderByFields = orderByComparator.getOrderByFields();
5068
5069 for (int i = 0; i < orderByFields.length; i++) {
5070 query.append(_ORDER_BY_ENTITY_ALIAS);
5071 query.append(orderByFields[i]);
5072
5073 if ((i + 1) < orderByFields.length) {
5074 if (orderByComparator.isAscending() ^ previous) {
5075 query.append(ORDER_BY_ASC_HAS_NEXT);
5076 }
5077 else {
5078 query.append(ORDER_BY_DESC_HAS_NEXT);
5079 }
5080 }
5081 else {
5082 if (orderByComparator.isAscending() ^ previous) {
5083 query.append(ORDER_BY_ASC);
5084 }
5085 else {
5086 query.append(ORDER_BY_DESC);
5087 }
5088 }
5089 }
5090 }
5091 else {
5092 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5093 }
5094
5095 String sql = query.toString();
5096
5097 Query q = session.createQuery(sql);
5098
5099 q.setFirstResult(0);
5100 q.setMaxResults(2);
5101
5102 QueryPos qPos = QueryPos.getInstance(q);
5103
5104 qPos.add(parentCategoryId);
5105
5106 if (bindName) {
5107 qPos.add(name);
5108 }
5109
5110 if (orderByComparator != null) {
5111 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5112
5113 for (Object value : values) {
5114 qPos.add(value);
5115 }
5116 }
5117
5118 List<AssetCategory> list = q.list();
5119
5120 if (list.size() == 2) {
5121 return list.get(1);
5122 }
5123 else {
5124 return null;
5125 }
5126 }
5127
5128
5135 public void removeByP_N(long parentCategoryId, String name)
5136 throws SystemException {
5137 for (AssetCategory assetCategory : findByP_N(parentCategoryId, name,
5138 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5139 remove(assetCategory);
5140 }
5141 }
5142
5143
5151 public int countByP_N(long parentCategoryId, String name)
5152 throws SystemException {
5153 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
5154
5155 Object[] finderArgs = new Object[] { parentCategoryId, name };
5156
5157 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5158 this);
5159
5160 if (count == null) {
5161 StringBundler query = new StringBundler(3);
5162
5163 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5164
5165 query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
5166
5167 boolean bindName = false;
5168
5169 if (name == null) {
5170 query.append(_FINDER_COLUMN_P_N_NAME_1);
5171 }
5172 else if (name.equals(StringPool.BLANK)) {
5173 query.append(_FINDER_COLUMN_P_N_NAME_3);
5174 }
5175 else {
5176 bindName = true;
5177
5178 query.append(_FINDER_COLUMN_P_N_NAME_2);
5179 }
5180
5181 String sql = query.toString();
5182
5183 Session session = null;
5184
5185 try {
5186 session = openSession();
5187
5188 Query q = session.createQuery(sql);
5189
5190 QueryPos qPos = QueryPos.getInstance(q);
5191
5192 qPos.add(parentCategoryId);
5193
5194 if (bindName) {
5195 qPos.add(name);
5196 }
5197
5198 count = (Long)q.uniqueResult();
5199
5200 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5201 }
5202 catch (Exception e) {
5203 FinderCacheUtil.removeResult(finderPath, finderArgs);
5204
5205 throw processException(e);
5206 }
5207 finally {
5208 closeSession(session);
5209 }
5210 }
5211
5212 return count.intValue();
5213 }
5214
5215 private static final String _FINDER_COLUMN_P_N_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5216 private static final String _FINDER_COLUMN_P_N_NAME_1 = "assetCategory.name IS NULL";
5217 private static final String _FINDER_COLUMN_P_N_NAME_2 = "assetCategory.name = ?";
5218 private static final String _FINDER_COLUMN_P_N_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '')";
5219 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5220 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5221 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5222 "findByP_V",
5223 new String[] {
5224 Long.class.getName(), Long.class.getName(),
5225
5226 Integer.class.getName(), Integer.class.getName(),
5227 OrderByComparator.class.getName()
5228 });
5229 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5230 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5231 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5232 "findByP_V",
5233 new String[] { Long.class.getName(), Long.class.getName() },
5234 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5235 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
5236 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
5237 public static final FinderPath FINDER_PATH_COUNT_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5238 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5239 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_V",
5240 new String[] { Long.class.getName(), Long.class.getName() });
5241
5242
5250 public List<AssetCategory> findByP_V(long parentCategoryId,
5251 long vocabularyId) throws SystemException {
5252 return findByP_V(parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
5253 QueryUtil.ALL_POS, null);
5254 }
5255
5256
5270 public List<AssetCategory> findByP_V(long parentCategoryId,
5271 long vocabularyId, int start, int end) throws SystemException {
5272 return findByP_V(parentCategoryId, vocabularyId, start, end, null);
5273 }
5274
5275
5290 public List<AssetCategory> findByP_V(long parentCategoryId,
5291 long vocabularyId, int start, int end,
5292 OrderByComparator orderByComparator) throws SystemException {
5293 boolean pagination = true;
5294 FinderPath finderPath = null;
5295 Object[] finderArgs = null;
5296
5297 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5298 (orderByComparator == null)) {
5299 pagination = false;
5300 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V;
5301 finderArgs = new Object[] { parentCategoryId, vocabularyId };
5302 }
5303 else {
5304 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V;
5305 finderArgs = new Object[] {
5306 parentCategoryId, vocabularyId,
5307
5308 start, end, orderByComparator
5309 };
5310 }
5311
5312 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
5313 finderArgs, this);
5314
5315 if ((list != null) && !list.isEmpty()) {
5316 for (AssetCategory assetCategory : list) {
5317 if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
5318 (vocabularyId != assetCategory.getVocabularyId())) {
5319 list = null;
5320
5321 break;
5322 }
5323 }
5324 }
5325
5326 if (list == null) {
5327 StringBundler query = null;
5328
5329 if (orderByComparator != null) {
5330 query = new StringBundler(4 +
5331 (orderByComparator.getOrderByFields().length * 3));
5332 }
5333 else {
5334 query = new StringBundler(4);
5335 }
5336
5337 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5338
5339 query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5340
5341 query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5342
5343 if (orderByComparator != null) {
5344 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5345 orderByComparator);
5346 }
5347 else
5348 if (pagination) {
5349 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5350 }
5351
5352 String sql = query.toString();
5353
5354 Session session = null;
5355
5356 try {
5357 session = openSession();
5358
5359 Query q = session.createQuery(sql);
5360
5361 QueryPos qPos = QueryPos.getInstance(q);
5362
5363 qPos.add(parentCategoryId);
5364
5365 qPos.add(vocabularyId);
5366
5367 if (!pagination) {
5368 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5369 start, end, false);
5370
5371 Collections.sort(list);
5372
5373 list = new UnmodifiableList<AssetCategory>(list);
5374 }
5375 else {
5376 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5377 start, end);
5378 }
5379
5380 cacheResult(list);
5381
5382 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5383 }
5384 catch (Exception e) {
5385 FinderCacheUtil.removeResult(finderPath, finderArgs);
5386
5387 throw processException(e);
5388 }
5389 finally {
5390 closeSession(session);
5391 }
5392 }
5393
5394 return list;
5395 }
5396
5397
5407 public AssetCategory findByP_V_First(long parentCategoryId,
5408 long vocabularyId, OrderByComparator orderByComparator)
5409 throws NoSuchCategoryException, SystemException {
5410 AssetCategory assetCategory = fetchByP_V_First(parentCategoryId,
5411 vocabularyId, orderByComparator);
5412
5413 if (assetCategory != null) {
5414 return assetCategory;
5415 }
5416
5417 StringBundler msg = new StringBundler(6);
5418
5419 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5420
5421 msg.append("parentCategoryId=");
5422 msg.append(parentCategoryId);
5423
5424 msg.append(", vocabularyId=");
5425 msg.append(vocabularyId);
5426
5427 msg.append(StringPool.CLOSE_CURLY_BRACE);
5428
5429 throw new NoSuchCategoryException(msg.toString());
5430 }
5431
5432
5441 public AssetCategory fetchByP_V_First(long parentCategoryId,
5442 long vocabularyId, OrderByComparator orderByComparator)
5443 throws SystemException {
5444 List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId, 0,
5445 1, orderByComparator);
5446
5447 if (!list.isEmpty()) {
5448 return list.get(0);
5449 }
5450
5451 return null;
5452 }
5453
5454
5464 public AssetCategory findByP_V_Last(long parentCategoryId,
5465 long vocabularyId, OrderByComparator orderByComparator)
5466 throws NoSuchCategoryException, SystemException {
5467 AssetCategory assetCategory = fetchByP_V_Last(parentCategoryId,
5468 vocabularyId, orderByComparator);
5469
5470 if (assetCategory != null) {
5471 return assetCategory;
5472 }
5473
5474 StringBundler msg = new StringBundler(6);
5475
5476 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5477
5478 msg.append("parentCategoryId=");
5479 msg.append(parentCategoryId);
5480
5481 msg.append(", vocabularyId=");
5482 msg.append(vocabularyId);
5483
5484 msg.append(StringPool.CLOSE_CURLY_BRACE);
5485
5486 throw new NoSuchCategoryException(msg.toString());
5487 }
5488
5489
5498 public AssetCategory fetchByP_V_Last(long parentCategoryId,
5499 long vocabularyId, OrderByComparator orderByComparator)
5500 throws SystemException {
5501 int count = countByP_V(parentCategoryId, vocabularyId);
5502
5503 List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId,
5504 count - 1, count, orderByComparator);
5505
5506 if (!list.isEmpty()) {
5507 return list.get(0);
5508 }
5509
5510 return null;
5511 }
5512
5513
5524 public AssetCategory[] findByP_V_PrevAndNext(long categoryId,
5525 long parentCategoryId, long vocabularyId,
5526 OrderByComparator orderByComparator)
5527 throws NoSuchCategoryException, SystemException {
5528 AssetCategory assetCategory = findByPrimaryKey(categoryId);
5529
5530 Session session = null;
5531
5532 try {
5533 session = openSession();
5534
5535 AssetCategory[] array = new AssetCategoryImpl[3];
5536
5537 array[0] = getByP_V_PrevAndNext(session, assetCategory,
5538 parentCategoryId, vocabularyId, orderByComparator, true);
5539
5540 array[1] = assetCategory;
5541
5542 array[2] = getByP_V_PrevAndNext(session, assetCategory,
5543 parentCategoryId, vocabularyId, orderByComparator, false);
5544
5545 return array;
5546 }
5547 catch (Exception e) {
5548 throw processException(e);
5549 }
5550 finally {
5551 closeSession(session);
5552 }
5553 }
5554
5555 protected AssetCategory getByP_V_PrevAndNext(Session session,
5556 AssetCategory assetCategory, long parentCategoryId, long vocabularyId,
5557 OrderByComparator orderByComparator, boolean previous) {
5558 StringBundler query = null;
5559
5560 if (orderByComparator != null) {
5561 query = new StringBundler(6 +
5562 (orderByComparator.getOrderByFields().length * 6));
5563 }
5564 else {
5565 query = new StringBundler(3);
5566 }
5567
5568 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5569
5570 query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5571
5572 query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5573
5574 if (orderByComparator != null) {
5575 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5576
5577 if (orderByConditionFields.length > 0) {
5578 query.append(WHERE_AND);
5579 }
5580
5581 for (int i = 0; i < orderByConditionFields.length; i++) {
5582 query.append(_ORDER_BY_ENTITY_ALIAS);
5583 query.append(orderByConditionFields[i]);
5584
5585 if ((i + 1) < orderByConditionFields.length) {
5586 if (orderByComparator.isAscending() ^ previous) {
5587 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5588 }
5589 else {
5590 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5591 }
5592 }
5593 else {
5594 if (orderByComparator.isAscending() ^ previous) {
5595 query.append(WHERE_GREATER_THAN);
5596 }
5597 else {
5598 query.append(WHERE_LESSER_THAN);
5599 }
5600 }
5601 }
5602
5603 query.append(ORDER_BY_CLAUSE);
5604
5605 String[] orderByFields = orderByComparator.getOrderByFields();
5606
5607 for (int i = 0; i < orderByFields.length; i++) {
5608 query.append(_ORDER_BY_ENTITY_ALIAS);
5609 query.append(orderByFields[i]);
5610
5611 if ((i + 1) < orderByFields.length) {
5612 if (orderByComparator.isAscending() ^ previous) {
5613 query.append(ORDER_BY_ASC_HAS_NEXT);
5614 }
5615 else {
5616 query.append(ORDER_BY_DESC_HAS_NEXT);
5617 }
5618 }
5619 else {
5620 if (orderByComparator.isAscending() ^ previous) {
5621 query.append(ORDER_BY_ASC);
5622 }
5623 else {
5624 query.append(ORDER_BY_DESC);
5625 }
5626 }
5627 }
5628 }
5629 else {
5630 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5631 }
5632
5633 String sql = query.toString();
5634
5635 Query q = session.createQuery(sql);
5636
5637 q.setFirstResult(0);
5638 q.setMaxResults(2);
5639
5640 QueryPos qPos = QueryPos.getInstance(q);
5641
5642 qPos.add(parentCategoryId);
5643
5644 qPos.add(vocabularyId);
5645
5646 if (orderByComparator != null) {
5647 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5648
5649 for (Object value : values) {
5650 qPos.add(value);
5651 }
5652 }
5653
5654 List<AssetCategory> list = q.list();
5655
5656 if (list.size() == 2) {
5657 return list.get(1);
5658 }
5659 else {
5660 return null;
5661 }
5662 }
5663
5664
5671 public void removeByP_V(long parentCategoryId, long vocabularyId)
5672 throws SystemException {
5673 for (AssetCategory assetCategory : findByP_V(parentCategoryId,
5674 vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5675 remove(assetCategory);
5676 }
5677 }
5678
5679
5687 public int countByP_V(long parentCategoryId, long vocabularyId)
5688 throws SystemException {
5689 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_V;
5690
5691 Object[] finderArgs = new Object[] { parentCategoryId, vocabularyId };
5692
5693 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5694 this);
5695
5696 if (count == null) {
5697 StringBundler query = new StringBundler(3);
5698
5699 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5700
5701 query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5702
5703 query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5704
5705 String sql = query.toString();
5706
5707 Session session = null;
5708
5709 try {
5710 session = openSession();
5711
5712 Query q = session.createQuery(sql);
5713
5714 QueryPos qPos = QueryPos.getInstance(q);
5715
5716 qPos.add(parentCategoryId);
5717
5718 qPos.add(vocabularyId);
5719
5720 count = (Long)q.uniqueResult();
5721
5722 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5723 }
5724 catch (Exception e) {
5725 FinderCacheUtil.removeResult(finderPath, finderArgs);
5726
5727 throw processException(e);
5728 }
5729 finally {
5730 closeSession(session);
5731 }
5732 }
5733
5734 return count.intValue();
5735 }
5736
5737 private static final String _FINDER_COLUMN_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5738 private static final String _FINDER_COLUMN_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5739 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5740 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5741 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5742 "findByN_V",
5743 new String[] {
5744 String.class.getName(), Long.class.getName(),
5745
5746 Integer.class.getName(), Integer.class.getName(),
5747 OrderByComparator.class.getName()
5748 });
5749 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5750 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5751 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5752 "findByN_V",
5753 new String[] { String.class.getName(), Long.class.getName() },
5754 AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
5755 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
5756 public static final FinderPath FINDER_PATH_COUNT_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5757 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5758 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_V",
5759 new String[] { String.class.getName(), Long.class.getName() });
5760
5761
5769 public List<AssetCategory> findByN_V(String name, long vocabularyId)
5770 throws SystemException {
5771 return findByN_V(name, vocabularyId, QueryUtil.ALL_POS,
5772 QueryUtil.ALL_POS, null);
5773 }
5774
5775
5789 public List<AssetCategory> findByN_V(String name, long vocabularyId,
5790 int start, int end) throws SystemException {
5791 return findByN_V(name, vocabularyId, start, end, null);
5792 }
5793
5794
5809 public List<AssetCategory> findByN_V(String name, long vocabularyId,
5810 int start, int end, OrderByComparator orderByComparator)
5811 throws SystemException {
5812 boolean pagination = true;
5813 FinderPath finderPath = null;
5814 Object[] finderArgs = null;
5815
5816 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5817 (orderByComparator == null)) {
5818 pagination = false;
5819 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V;
5820 finderArgs = new Object[] { name, vocabularyId };
5821 }
5822 else {
5823 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V;
5824 finderArgs = new Object[] {
5825 name, vocabularyId,
5826
5827 start, end, orderByComparator
5828 };
5829 }
5830
5831 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
5832 finderArgs, this);
5833
5834 if ((list != null) && !list.isEmpty()) {
5835 for (AssetCategory assetCategory : list) {
5836 if (!Validator.equals(name, assetCategory.getName()) ||
5837 (vocabularyId != assetCategory.getVocabularyId())) {
5838 list = null;
5839
5840 break;
5841 }
5842 }
5843 }
5844
5845 if (list == null) {
5846 StringBundler query = null;
5847
5848 if (orderByComparator != null) {
5849 query = new StringBundler(4 +
5850 (orderByComparator.getOrderByFields().length * 3));
5851 }
5852 else {
5853 query = new StringBundler(4);
5854 }
5855
5856 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5857
5858 boolean bindName = false;
5859
5860 if (name == null) {
5861 query.append(_FINDER_COLUMN_N_V_NAME_1);
5862 }
5863 else if (name.equals(StringPool.BLANK)) {
5864 query.append(_FINDER_COLUMN_N_V_NAME_3);
5865 }
5866 else {
5867 bindName = true;
5868
5869 query.append(_FINDER_COLUMN_N_V_NAME_2);
5870 }
5871
5872 query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
5873
5874 if (orderByComparator != null) {
5875 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5876 orderByComparator);
5877 }
5878 else
5879 if (pagination) {
5880 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5881 }
5882
5883 String sql = query.toString();
5884
5885 Session session = null;
5886
5887 try {
5888 session = openSession();
5889
5890 Query q = session.createQuery(sql);
5891
5892 QueryPos qPos = QueryPos.getInstance(q);
5893
5894 if (bindName) {
5895 qPos.add(name);
5896 }
5897
5898 qPos.add(vocabularyId);
5899
5900 if (!pagination) {
5901 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5902 start, end, false);
5903
5904 Collections.sort(list);
5905
5906 list = new UnmodifiableList<AssetCategory>(list);
5907 }
5908 else {
5909 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5910 start, end);
5911 }
5912
5913 cacheResult(list);
5914
5915 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5916 }
5917 catch (Exception e) {
5918 FinderCacheUtil.removeResult(finderPath, finderArgs);
5919
5920 throw processException(e);
5921 }
5922 finally {
5923 closeSession(session);
5924 }
5925 }
5926
5927 return list;
5928 }
5929
5930
5940 public AssetCategory findByN_V_First(String name, long vocabularyId,
5941 OrderByComparator orderByComparator)
5942 throws NoSuchCategoryException, SystemException {
5943 AssetCategory assetCategory = fetchByN_V_First(name, vocabularyId,
5944 orderByComparator);
5945
5946 if (assetCategory != null) {
5947 return assetCategory;
5948 }
5949
5950 StringBundler msg = new StringBundler(6);
5951
5952 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5953
5954 msg.append("name=");
5955 msg.append(name);
5956
5957 msg.append(", vocabularyId=");
5958 msg.append(vocabularyId);
5959
5960 msg.append(StringPool.CLOSE_CURLY_BRACE);
5961
5962 throw new NoSuchCategoryException(msg.toString());
5963 }
5964
5965
5974 public AssetCategory fetchByN_V_First(String name, long vocabularyId,
5975 OrderByComparator orderByComparator) throws SystemException {
5976 List<AssetCategory> list = findByN_V(name, vocabularyId, 0, 1,
5977 orderByComparator);
5978
5979 if (!list.isEmpty()) {
5980 return list.get(0);
5981 }
5982
5983 return null;
5984 }
5985
5986
5996 public AssetCategory findByN_V_Last(String name, long vocabularyId,
5997 OrderByComparator orderByComparator)
5998 throws NoSuchCategoryException, SystemException {
5999 AssetCategory assetCategory = fetchByN_V_Last(name, vocabularyId,
6000 orderByComparator);
6001
6002 if (assetCategory != null) {
6003 return assetCategory;
6004 }
6005
6006 StringBundler msg = new StringBundler(6);
6007
6008 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6009
6010 msg.append("name=");
6011 msg.append(name);
6012
6013 msg.append(", vocabularyId=");
6014 msg.append(vocabularyId);
6015
6016 msg.append(StringPool.CLOSE_CURLY_BRACE);
6017
6018 throw new NoSuchCategoryException(msg.toString());
6019 }
6020
6021
6030 public AssetCategory fetchByN_V_Last(String name, long vocabularyId,
6031 OrderByComparator orderByComparator) throws SystemException {
6032 int count = countByN_V(name, vocabularyId);
6033
6034 List<AssetCategory> list = findByN_V(name, vocabularyId, count - 1,
6035 count, orderByComparator);
6036
6037 if (!list.isEmpty()) {
6038 return list.get(0);
6039 }
6040
6041 return null;
6042 }
6043
6044
6055 public AssetCategory[] findByN_V_PrevAndNext(long categoryId, String name,
6056 long vocabularyId, OrderByComparator orderByComparator)
6057 throws NoSuchCategoryException, SystemException {
6058 AssetCategory assetCategory = findByPrimaryKey(categoryId);
6059
6060 Session session = null;
6061
6062 try {
6063 session = openSession();
6064
6065 AssetCategory[] array = new AssetCategoryImpl[3];
6066
6067 array[0] = getByN_V_PrevAndNext(session, assetCategory, name,
6068 vocabularyId, orderByComparator, true);
6069
6070 array[1] = assetCategory;
6071
6072 array[2] = getByN_V_PrevAndNext(session, assetCategory, name,
6073 vocabularyId, orderByComparator, false);
6074
6075 return array;
6076 }
6077 catch (Exception e) {
6078 throw processException(e);
6079 }
6080 finally {
6081 closeSession(session);
6082 }
6083 }
6084
6085 protected AssetCategory getByN_V_PrevAndNext(Session session,
6086 AssetCategory assetCategory, String name, long vocabularyId,
6087 OrderByComparator orderByComparator, boolean previous) {
6088 StringBundler query = null;
6089
6090 if (orderByComparator != null) {
6091 query = new StringBundler(6 +
6092 (orderByComparator.getOrderByFields().length * 6));
6093 }
6094 else {
6095 query = new StringBundler(3);
6096 }
6097
6098 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6099
6100 boolean bindName = false;
6101
6102 if (name == null) {
6103 query.append(_FINDER_COLUMN_N_V_NAME_1);
6104 }
6105 else if (name.equals(StringPool.BLANK)) {
6106 query.append(_FINDER_COLUMN_N_V_NAME_3);
6107 }
6108 else {
6109 bindName = true;
6110
6111 query.append(_FINDER_COLUMN_N_V_NAME_2);
6112 }
6113
6114 query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6115
6116 if (orderByComparator != null) {
6117 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6118
6119 if (orderByConditionFields.length > 0) {
6120 query.append(WHERE_AND);
6121 }
6122
6123 for (int i = 0; i < orderByConditionFields.length; i++) {
6124 query.append(_ORDER_BY_ENTITY_ALIAS);
6125 query.append(orderByConditionFields[i]);
6126
6127 if ((i + 1) < orderByConditionFields.length) {
6128 if (orderByComparator.isAscending() ^ previous) {
6129 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6130 }
6131 else {
6132 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6133 }
6134 }
6135 else {
6136 if (orderByComparator.isAscending() ^ previous) {
6137 query.append(WHERE_GREATER_THAN);
6138 }
6139 else {
6140 query.append(WHERE_LESSER_THAN);
6141 }
6142 }
6143 }
6144
6145 query.append(ORDER_BY_CLAUSE);
6146
6147 String[] orderByFields = orderByComparator.getOrderByFields();
6148
6149 for (int i = 0; i < orderByFields.length; i++) {
6150 query.append(_ORDER_BY_ENTITY_ALIAS);
6151 query.append(orderByFields[i]);
6152
6153 if ((i + 1) < orderByFields.length) {
6154 if (orderByComparator.isAscending() ^ previous) {
6155 query.append(ORDER_BY_ASC_HAS_NEXT);
6156 }
6157 else {
6158 query.append(ORDER_BY_DESC_HAS_NEXT);
6159 }
6160 }
6161 else {
6162 if (orderByComparator.isAscending() ^ previous) {
6163 query.append(ORDER_BY_ASC);
6164 }
6165 else {
6166 query.append(ORDER_BY_DESC);
6167 }
6168 }
6169 }
6170 }
6171 else {
6172 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6173 }
6174
6175 String sql = query.toString();
6176
6177 Query q = session.createQuery(sql);
6178
6179 q.setFirstResult(0);
6180 q.setMaxResults(2);
6181
6182 QueryPos qPos = QueryPos.getInstance(q);
6183
6184 if (bindName) {
6185 qPos.add(name);
6186 }
6187
6188 qPos.add(vocabularyId);
6189
6190 if (orderByComparator != null) {
6191 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6192
6193 for (Object value : values) {
6194 qPos.add(value);
6195 }
6196 }
6197
6198 List<AssetCategory> list = q.list();
6199
6200 if (list.size() == 2) {
6201 return list.get(1);
6202 }
6203 else {
6204 return null;
6205 }
6206 }
6207
6208
6215 public void removeByN_V(String name, long vocabularyId)
6216 throws SystemException {
6217 for (AssetCategory assetCategory : findByN_V(name, vocabularyId,
6218 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6219 remove(assetCategory);
6220 }
6221 }
6222
6223
6231 public int countByN_V(String name, long vocabularyId)
6232 throws SystemException {
6233 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_V;
6234
6235 Object[] finderArgs = new Object[] { name, vocabularyId };
6236
6237 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6238 this);
6239
6240 if (count == null) {
6241 StringBundler query = new StringBundler(3);
6242
6243 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
6244
6245 boolean bindName = false;
6246
6247 if (name == null) {
6248 query.append(_FINDER_COLUMN_N_V_NAME_1);
6249 }
6250 else if (name.equals(StringPool.BLANK)) {
6251 query.append(_FINDER_COLUMN_N_V_NAME_3);
6252 }
6253 else {
6254 bindName = true;
6255
6256 query.append(_FINDER_COLUMN_N_V_NAME_2);
6257 }
6258
6259 query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6260
6261 String sql = query.toString();
6262
6263 Session session = null;
6264
6265 try {
6266 session = openSession();
6267
6268 Query q = session.createQuery(sql);
6269
6270 QueryPos qPos = QueryPos.getInstance(q);
6271
6272 if (bindName) {
6273 qPos.add(name);
6274 }
6275
6276 qPos.add(vocabularyId);
6277
6278 count = (Long)q.uniqueResult();
6279
6280 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6281 }
6282 catch (Exception e) {
6283 FinderCacheUtil.removeResult(finderPath, finderArgs);
6284
6285 throw processException(e);
6286 }
6287 finally {
6288 closeSession(session);
6289 }
6290 }
6291
6292 return count.intValue();
6293 }
6294
6295 private static final String _FINDER_COLUMN_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
6296 private static final String _FINDER_COLUMN_N_V_NAME_2 = "assetCategory.name = ? AND ";
6297 private static final String _FINDER_COLUMN_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
6298 private static final String _FINDER_COLUMN_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
6299 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V =
6300 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6301 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6302 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6303 "findByG_LikeN_V",
6304 new String[] {
6305 Long.class.getName(), String.class.getName(),
6306 Long.class.getName(),
6307
6308 Integer.class.getName(), Integer.class.getName(),
6309 OrderByComparator.class.getName()
6310 });
6311 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V =
6312 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6313 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6314 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LikeN_V",
6315 new String[] {
6316 Long.class.getName(), String.class.getName(),
6317 Long.class.getName()
6318 });
6319
6320
6329 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
6330 long vocabularyId) throws SystemException {
6331 return findByG_LikeN_V(groupId, name, vocabularyId, QueryUtil.ALL_POS,
6332 QueryUtil.ALL_POS, null);
6333 }
6334
6335
6350 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
6351 long vocabularyId, int start, int end) throws SystemException {
6352 return findByG_LikeN_V(groupId, name, vocabularyId, start, end, null);
6353 }
6354
6355
6371 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
6372 long vocabularyId, int start, int end,
6373 OrderByComparator orderByComparator) throws SystemException {
6374 boolean pagination = true;
6375 FinderPath finderPath = null;
6376 Object[] finderArgs = null;
6377
6378 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V;
6379 finderArgs = new Object[] {
6380 groupId, name, vocabularyId,
6381
6382 start, end, orderByComparator
6383 };
6384
6385 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
6386 finderArgs, this);
6387
6388 if ((list != null) && !list.isEmpty()) {
6389 for (AssetCategory assetCategory : list) {
6390 if ((groupId != assetCategory.getGroupId()) ||
6391 !Validator.equals(name, assetCategory.getName()) ||
6392 (vocabularyId != assetCategory.getVocabularyId())) {
6393 list = null;
6394
6395 break;
6396 }
6397 }
6398 }
6399
6400 if (list == null) {
6401 StringBundler query = null;
6402
6403 if (orderByComparator != null) {
6404 query = new StringBundler(5 +
6405 (orderByComparator.getOrderByFields().length * 3));
6406 }
6407 else {
6408 query = new StringBundler(5);
6409 }
6410
6411 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6412
6413 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
6414
6415 boolean bindName = false;
6416
6417 if (name == null) {
6418 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
6419 }
6420 else if (name.equals(StringPool.BLANK)) {
6421 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
6422 }
6423 else {
6424 bindName = true;
6425
6426 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
6427 }
6428
6429 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
6430
6431 if (orderByComparator != null) {
6432 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6433 orderByComparator);
6434 }
6435 else
6436 if (pagination) {
6437 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6438 }
6439
6440 String sql = query.toString();
6441
6442 Session session = null;
6443
6444 try {
6445 session = openSession();
6446
6447 Query q = session.createQuery(sql);
6448
6449 QueryPos qPos = QueryPos.getInstance(q);
6450
6451 qPos.add(groupId);
6452
6453 if (bindName) {
6454 qPos.add(name);
6455 }
6456
6457 qPos.add(vocabularyId);
6458
6459 if (!pagination) {
6460 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6461 start, end, false);
6462
6463 Collections.sort(list);
6464
6465 list = new UnmodifiableList<AssetCategory>(list);
6466 }
6467 else {
6468 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6469 start, end);
6470 }
6471
6472 cacheResult(list);
6473
6474 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6475 }
6476 catch (Exception e) {
6477 FinderCacheUtil.removeResult(finderPath, finderArgs);
6478
6479 throw processException(e);
6480 }
6481 finally {
6482 closeSession(session);
6483 }
6484 }
6485
6486 return list;
6487 }
6488
6489
6500 public AssetCategory findByG_LikeN_V_First(long groupId, String name,
6501 long vocabularyId, OrderByComparator orderByComparator)
6502 throws NoSuchCategoryException, SystemException {
6503 AssetCategory assetCategory = fetchByG_LikeN_V_First(groupId, name,
6504 vocabularyId, orderByComparator);
6505
6506 if (assetCategory != null) {
6507 return assetCategory;
6508 }
6509
6510 StringBundler msg = new StringBundler(8);
6511
6512 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6513
6514 msg.append("groupId=");
6515 msg.append(groupId);
6516
6517 msg.append(", name=");
6518 msg.append(name);
6519
6520 msg.append(", vocabularyId=");
6521 msg.append(vocabularyId);
6522
6523 msg.append(StringPool.CLOSE_CURLY_BRACE);
6524
6525 throw new NoSuchCategoryException(msg.toString());
6526 }
6527
6528
6538 public AssetCategory fetchByG_LikeN_V_First(long groupId, String name,
6539 long vocabularyId, OrderByComparator orderByComparator)
6540 throws SystemException {
6541 List<AssetCategory> list = findByG_LikeN_V(groupId, name, vocabularyId,
6542 0, 1, orderByComparator);
6543
6544 if (!list.isEmpty()) {
6545 return list.get(0);
6546 }
6547
6548 return null;
6549 }
6550
6551
6562 public AssetCategory findByG_LikeN_V_Last(long groupId, String name,
6563 long vocabularyId, OrderByComparator orderByComparator)
6564 throws NoSuchCategoryException, SystemException {
6565 AssetCategory assetCategory = fetchByG_LikeN_V_Last(groupId, name,
6566 vocabularyId, orderByComparator);
6567
6568 if (assetCategory != null) {
6569 return assetCategory;
6570 }
6571
6572 StringBundler msg = new StringBundler(8);
6573
6574 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6575
6576 msg.append("groupId=");
6577 msg.append(groupId);
6578
6579 msg.append(", name=");
6580 msg.append(name);
6581
6582 msg.append(", vocabularyId=");
6583 msg.append(vocabularyId);
6584
6585 msg.append(StringPool.CLOSE_CURLY_BRACE);
6586
6587 throw new NoSuchCategoryException(msg.toString());
6588 }
6589
6590
6600 public AssetCategory fetchByG_LikeN_V_Last(long groupId, String name,
6601 long vocabularyId, OrderByComparator orderByComparator)
6602 throws SystemException {
6603 int count = countByG_LikeN_V(groupId, name, vocabularyId);
6604
6605 List<AssetCategory> list = findByG_LikeN_V(groupId, name, vocabularyId,
6606 count - 1, count, orderByComparator);
6607
6608 if (!list.isEmpty()) {
6609 return list.get(0);
6610 }
6611
6612 return null;
6613 }
6614
6615
6627 public AssetCategory[] findByG_LikeN_V_PrevAndNext(long categoryId,
6628 long groupId, String name, long vocabularyId,
6629 OrderByComparator orderByComparator)
6630 throws NoSuchCategoryException, SystemException {
6631 AssetCategory assetCategory = findByPrimaryKey(categoryId);
6632
6633 Session session = null;
6634
6635 try {
6636 session = openSession();
6637
6638 AssetCategory[] array = new AssetCategoryImpl[3];
6639
6640 array[0] = getByG_LikeN_V_PrevAndNext(session, assetCategory,
6641 groupId, name, vocabularyId, orderByComparator, true);
6642
6643 array[1] = assetCategory;
6644
6645 array[2] = getByG_LikeN_V_PrevAndNext(session, assetCategory,
6646 groupId, name, vocabularyId, orderByComparator, false);
6647
6648 return array;
6649 }
6650 catch (Exception e) {
6651 throw processException(e);
6652 }
6653 finally {
6654 closeSession(session);
6655 }
6656 }
6657
6658 protected AssetCategory getByG_LikeN_V_PrevAndNext(Session session,
6659 AssetCategory assetCategory, long groupId, String name,
6660 long vocabularyId, OrderByComparator orderByComparator, boolean previous) {
6661 StringBundler query = null;
6662
6663 if (orderByComparator != null) {
6664 query = new StringBundler(6 +
6665 (orderByComparator.getOrderByFields().length * 6));
6666 }
6667 else {
6668 query = new StringBundler(3);
6669 }
6670
6671 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6672
6673 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
6674
6675 boolean bindName = false;
6676
6677 if (name == null) {
6678 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
6679 }
6680 else if (name.equals(StringPool.BLANK)) {
6681 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
6682 }
6683 else {
6684 bindName = true;
6685
6686 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
6687 }
6688
6689 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
6690
6691 if (orderByComparator != null) {
6692 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6693
6694 if (orderByConditionFields.length > 0) {
6695 query.append(WHERE_AND);
6696 }
6697
6698 for (int i = 0; i < orderByConditionFields.length; i++) {
6699 query.append(_ORDER_BY_ENTITY_ALIAS);
6700 query.append(orderByConditionFields[i]);
6701
6702 if ((i + 1) < orderByConditionFields.length) {
6703 if (orderByComparator.isAscending() ^ previous) {
6704 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6705 }
6706 else {
6707 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6708 }
6709 }
6710 else {
6711 if (orderByComparator.isAscending() ^ previous) {
6712 query.append(WHERE_GREATER_THAN);
6713 }
6714 else {
6715 query.append(WHERE_LESSER_THAN);
6716 }
6717 }
6718 }
6719
6720 query.append(ORDER_BY_CLAUSE);
6721
6722 String[] orderByFields = orderByComparator.getOrderByFields();
6723
6724 for (int i = 0; i < orderByFields.length; i++) {
6725 query.append(_ORDER_BY_ENTITY_ALIAS);
6726 query.append(orderByFields[i]);
6727
6728 if ((i + 1) < orderByFields.length) {
6729 if (orderByComparator.isAscending() ^ previous) {
6730 query.append(ORDER_BY_ASC_HAS_NEXT);
6731 }
6732 else {
6733 query.append(ORDER_BY_DESC_HAS_NEXT);
6734 }
6735 }
6736 else {
6737 if (orderByComparator.isAscending() ^ previous) {
6738 query.append(ORDER_BY_ASC);
6739 }
6740 else {
6741 query.append(ORDER_BY_DESC);
6742 }
6743 }
6744 }
6745 }
6746 else {
6747 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6748 }
6749
6750 String sql = query.toString();
6751
6752 Query q = session.createQuery(sql);
6753
6754 q.setFirstResult(0);
6755 q.setMaxResults(2);
6756
6757 QueryPos qPos = QueryPos.getInstance(q);
6758
6759 qPos.add(groupId);
6760
6761 if (bindName) {
6762 qPos.add(name);
6763 }
6764
6765 qPos.add(vocabularyId);
6766
6767 if (orderByComparator != null) {
6768 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6769
6770 for (Object value : values) {
6771 qPos.add(value);
6772 }
6773 }
6774
6775 List<AssetCategory> list = q.list();
6776
6777 if (list.size() == 2) {
6778 return list.get(1);
6779 }
6780 else {
6781 return null;
6782 }
6783 }
6784
6785
6794 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
6795 long vocabularyId) throws SystemException {
6796 return filterFindByG_LikeN_V(groupId, name, vocabularyId,
6797 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6798 }
6799
6800
6815 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
6816 long vocabularyId, int start, int end) throws SystemException {
6817 return filterFindByG_LikeN_V(groupId, name, vocabularyId, start, end,
6818 null);
6819 }
6820
6821
6837 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
6838 long vocabularyId, int start, int end,
6839 OrderByComparator orderByComparator) throws SystemException {
6840 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6841 return findByG_LikeN_V(groupId, name, vocabularyId, start, end,
6842 orderByComparator);
6843 }
6844
6845 StringBundler query = null;
6846
6847 if (orderByComparator != null) {
6848 query = new StringBundler(5 +
6849 (orderByComparator.getOrderByFields().length * 3));
6850 }
6851 else {
6852 query = new StringBundler(5);
6853 }
6854
6855 if (getDB().isSupportsInlineDistinct()) {
6856 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
6857 }
6858 else {
6859 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6860 }
6861
6862 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
6863
6864 boolean bindName = false;
6865
6866 if (name == null) {
6867 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
6868 }
6869 else if (name.equals(StringPool.BLANK)) {
6870 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
6871 }
6872 else {
6873 bindName = true;
6874
6875 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
6876 }
6877
6878 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
6879
6880 if (!getDB().isSupportsInlineDistinct()) {
6881 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6882 }
6883
6884 if (orderByComparator != null) {
6885 if (getDB().isSupportsInlineDistinct()) {
6886 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6887 orderByComparator);
6888 }
6889 else {
6890 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6891 orderByComparator);
6892 }
6893 }
6894 else {
6895 if (getDB().isSupportsInlineDistinct()) {
6896 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6897 }
6898 else {
6899 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
6900 }
6901 }
6902
6903 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6904 AssetCategory.class.getName(),
6905 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6906
6907 Session session = null;
6908
6909 try {
6910 session = openSession();
6911
6912 SQLQuery q = session.createSQLQuery(sql);
6913
6914 if (getDB().isSupportsInlineDistinct()) {
6915 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
6916 }
6917 else {
6918 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
6919 }
6920
6921 QueryPos qPos = QueryPos.getInstance(q);
6922
6923 qPos.add(groupId);
6924
6925 if (bindName) {
6926 qPos.add(name);
6927 }
6928
6929 qPos.add(vocabularyId);
6930
6931 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
6932 end);
6933 }
6934 catch (Exception e) {
6935 throw processException(e);
6936 }
6937 finally {
6938 closeSession(session);
6939 }
6940 }
6941
6942
6954 public AssetCategory[] filterFindByG_LikeN_V_PrevAndNext(long categoryId,
6955 long groupId, String name, long vocabularyId,
6956 OrderByComparator orderByComparator)
6957 throws NoSuchCategoryException, SystemException {
6958 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6959 return findByG_LikeN_V_PrevAndNext(categoryId, groupId, name,
6960 vocabularyId, orderByComparator);
6961 }
6962
6963 AssetCategory assetCategory = findByPrimaryKey(categoryId);
6964
6965 Session session = null;
6966
6967 try {
6968 session = openSession();
6969
6970 AssetCategory[] array = new AssetCategoryImpl[3];
6971
6972 array[0] = filterGetByG_LikeN_V_PrevAndNext(session, assetCategory,
6973 groupId, name, vocabularyId, orderByComparator, true);
6974
6975 array[1] = assetCategory;
6976
6977 array[2] = filterGetByG_LikeN_V_PrevAndNext(session, assetCategory,
6978 groupId, name, vocabularyId, orderByComparator, false);
6979
6980 return array;
6981 }
6982 catch (Exception e) {
6983 throw processException(e);
6984 }
6985 finally {
6986 closeSession(session);
6987 }
6988 }
6989
6990 protected AssetCategory filterGetByG_LikeN_V_PrevAndNext(Session session,
6991 AssetCategory assetCategory, long groupId, String name,
6992 long vocabularyId, OrderByComparator orderByComparator, boolean previous) {
6993 StringBundler query = null;
6994
6995 if (orderByComparator != null) {
6996 query = new StringBundler(6 +
6997 (orderByComparator.getOrderByFields().length * 6));
6998 }
6999 else {
7000 query = new StringBundler(3);
7001 }
7002
7003 if (getDB().isSupportsInlineDistinct()) {
7004 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
7005 }
7006 else {
7007 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7008 }
7009
7010 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7011
7012 boolean bindName = false;
7013
7014 if (name == null) {
7015 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7016 }
7017 else if (name.equals(StringPool.BLANK)) {
7018 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7019 }
7020 else {
7021 bindName = true;
7022
7023 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7024 }
7025
7026 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7027
7028 if (!getDB().isSupportsInlineDistinct()) {
7029 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7030 }
7031
7032 if (orderByComparator != null) {
7033 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7034
7035 if (orderByConditionFields.length > 0) {
7036 query.append(WHERE_AND);
7037 }
7038
7039 for (int i = 0; i < orderByConditionFields.length; i++) {
7040 if (getDB().isSupportsInlineDistinct()) {
7041 query.append(_ORDER_BY_ENTITY_ALIAS);
7042 }
7043 else {
7044 query.append(_ORDER_BY_ENTITY_TABLE);
7045 }
7046
7047 query.append(orderByConditionFields[i]);
7048
7049 if ((i + 1) < orderByConditionFields.length) {
7050 if (orderByComparator.isAscending() ^ previous) {
7051 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7052 }
7053 else {
7054 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7055 }
7056 }
7057 else {
7058 if (orderByComparator.isAscending() ^ previous) {
7059 query.append(WHERE_GREATER_THAN);
7060 }
7061 else {
7062 query.append(WHERE_LESSER_THAN);
7063 }
7064 }
7065 }
7066
7067 query.append(ORDER_BY_CLAUSE);
7068
7069 String[] orderByFields = orderByComparator.getOrderByFields();
7070
7071 for (int i = 0; i < orderByFields.length; i++) {
7072 if (getDB().isSupportsInlineDistinct()) {
7073 query.append(_ORDER_BY_ENTITY_ALIAS);
7074 }
7075 else {
7076 query.append(_ORDER_BY_ENTITY_TABLE);
7077 }
7078
7079 query.append(orderByFields[i]);
7080
7081 if ((i + 1) < orderByFields.length) {
7082 if (orderByComparator.isAscending() ^ previous) {
7083 query.append(ORDER_BY_ASC_HAS_NEXT);
7084 }
7085 else {
7086 query.append(ORDER_BY_DESC_HAS_NEXT);
7087 }
7088 }
7089 else {
7090 if (orderByComparator.isAscending() ^ previous) {
7091 query.append(ORDER_BY_ASC);
7092 }
7093 else {
7094 query.append(ORDER_BY_DESC);
7095 }
7096 }
7097 }
7098 }
7099 else {
7100 if (getDB().isSupportsInlineDistinct()) {
7101 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7102 }
7103 else {
7104 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
7105 }
7106 }
7107
7108 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7109 AssetCategory.class.getName(),
7110 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7111
7112 SQLQuery q = session.createSQLQuery(sql);
7113
7114 q.setFirstResult(0);
7115 q.setMaxResults(2);
7116
7117 if (getDB().isSupportsInlineDistinct()) {
7118 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
7119 }
7120 else {
7121 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
7122 }
7123
7124 QueryPos qPos = QueryPos.getInstance(q);
7125
7126 qPos.add(groupId);
7127
7128 if (bindName) {
7129 qPos.add(name);
7130 }
7131
7132 qPos.add(vocabularyId);
7133
7134 if (orderByComparator != null) {
7135 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
7136
7137 for (Object value : values) {
7138 qPos.add(value);
7139 }
7140 }
7141
7142 List<AssetCategory> list = q.list();
7143
7144 if (list.size() == 2) {
7145 return list.get(1);
7146 }
7147 else {
7148 return null;
7149 }
7150 }
7151
7152
7161 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
7162 long[] vocabularyIds) throws SystemException {
7163 return filterFindByG_LikeN_V(groupId, name, vocabularyIds,
7164 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7165 }
7166
7167
7182 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
7183 long[] vocabularyIds, int start, int end) throws SystemException {
7184 return filterFindByG_LikeN_V(groupId, name, vocabularyIds, start, end,
7185 null);
7186 }
7187
7188
7204 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
7205 long[] vocabularyIds, int start, int end,
7206 OrderByComparator orderByComparator) throws SystemException {
7207 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7208 return findByG_LikeN_V(groupId, name, vocabularyIds, start, end,
7209 orderByComparator);
7210 }
7211
7212 StringBundler query = new StringBundler();
7213
7214 if (getDB().isSupportsInlineDistinct()) {
7215 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
7216 }
7217 else {
7218 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7219 }
7220
7221 boolean conjunctionable = false;
7222
7223 if (conjunctionable) {
7224 query.append(WHERE_AND);
7225 }
7226
7227 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
7228
7229 conjunctionable = true;
7230
7231 if (conjunctionable) {
7232 query.append(WHERE_AND);
7233 }
7234
7235 if (name == null) {
7236 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
7237 }
7238 else if (name.equals(StringPool.BLANK)) {
7239 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
7240 }
7241 else {
7242 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
7243 }
7244
7245 conjunctionable = true;
7246
7247 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
7248 if (conjunctionable) {
7249 query.append(WHERE_AND);
7250 }
7251
7252 query.append(StringPool.OPEN_PARENTHESIS);
7253
7254 for (int i = 0; i < vocabularyIds.length; i++) {
7255 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
7256
7257 if ((i + 1) < vocabularyIds.length) {
7258 query.append(WHERE_OR);
7259 }
7260 }
7261
7262 query.append(StringPool.CLOSE_PARENTHESIS);
7263
7264 conjunctionable = true;
7265 }
7266
7267 if (!getDB().isSupportsInlineDistinct()) {
7268 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7269 }
7270
7271 if (orderByComparator != null) {
7272 if (getDB().isSupportsInlineDistinct()) {
7273 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7274 orderByComparator);
7275 }
7276 else {
7277 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7278 orderByComparator);
7279 }
7280 }
7281 else {
7282 if (getDB().isSupportsInlineDistinct()) {
7283 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7284 }
7285 else {
7286 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
7287 }
7288 }
7289
7290 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7291 AssetCategory.class.getName(),
7292 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7293
7294 Session session = null;
7295
7296 try {
7297 session = openSession();
7298
7299 SQLQuery q = session.createSQLQuery(sql);
7300
7301 if (getDB().isSupportsInlineDistinct()) {
7302 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
7303 }
7304 else {
7305 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
7306 }
7307
7308 QueryPos qPos = QueryPos.getInstance(q);
7309
7310 qPos.add(groupId);
7311
7312 if (name != null) {
7313 qPos.add(name);
7314 }
7315
7316 if (vocabularyIds != null) {
7317 qPos.add(vocabularyIds);
7318 }
7319
7320 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
7321 end);
7322 }
7323 catch (Exception e) {
7324 throw processException(e);
7325 }
7326 finally {
7327 closeSession(session);
7328 }
7329 }
7330
7331
7344 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7345 long[] vocabularyIds) throws SystemException {
7346 return findByG_LikeN_V(groupId, name, vocabularyIds, QueryUtil.ALL_POS,
7347 QueryUtil.ALL_POS, null);
7348 }
7349
7350
7365 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7366 long[] vocabularyIds, int start, int end) throws SystemException {
7367 return findByG_LikeN_V(groupId, name, vocabularyIds, start, end, null);
7368 }
7369
7370
7386 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7387 long[] vocabularyIds, int start, int end,
7388 OrderByComparator orderByComparator) throws SystemException {
7389 if ((vocabularyIds != null) && (vocabularyIds.length == 1)) {
7390 return findByG_LikeN_V(groupId, name, vocabularyIds[0], start, end,
7391 orderByComparator);
7392 }
7393
7394 boolean pagination = true;
7395 Object[] finderArgs = null;
7396
7397 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7398 (orderByComparator == null)) {
7399 pagination = false;
7400 finderArgs = new Object[] {
7401 groupId, name, StringUtil.merge(vocabularyIds)
7402 };
7403 }
7404 else {
7405 finderArgs = new Object[] {
7406 groupId, name, StringUtil.merge(vocabularyIds),
7407
7408 start, end, orderByComparator
7409 };
7410 }
7411
7412 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
7413 finderArgs, this);
7414
7415 if ((list != null) && !list.isEmpty()) {
7416 for (AssetCategory assetCategory : list) {
7417 if ((groupId != assetCategory.getGroupId()) ||
7418 !Validator.equals(name, assetCategory.getName()) ||
7419 !ArrayUtil.contains(vocabularyIds,
7420 assetCategory.getVocabularyId())) {
7421 list = null;
7422
7423 break;
7424 }
7425 }
7426 }
7427
7428 if (list == null) {
7429 StringBundler query = new StringBundler();
7430
7431 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
7432
7433 boolean conjunctionable = false;
7434
7435 if (conjunctionable) {
7436 query.append(WHERE_AND);
7437 }
7438
7439 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
7440
7441 conjunctionable = true;
7442
7443 if (conjunctionable) {
7444 query.append(WHERE_AND);
7445 }
7446
7447 if (name == null) {
7448 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
7449 }
7450 else if (name.equals(StringPool.BLANK)) {
7451 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
7452 }
7453 else {
7454 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
7455 }
7456
7457 conjunctionable = true;
7458
7459 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
7460 if (conjunctionable) {
7461 query.append(WHERE_AND);
7462 }
7463
7464 query.append(StringPool.OPEN_PARENTHESIS);
7465
7466 for (int i = 0; i < vocabularyIds.length; i++) {
7467 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
7468
7469 if ((i + 1) < vocabularyIds.length) {
7470 query.append(WHERE_OR);
7471 }
7472 }
7473
7474 query.append(StringPool.CLOSE_PARENTHESIS);
7475
7476 conjunctionable = true;
7477 }
7478
7479 if (orderByComparator != null) {
7480 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7481 orderByComparator);
7482 }
7483 else
7484 if (pagination) {
7485 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7486 }
7487
7488 String sql = query.toString();
7489
7490 Session session = null;
7491
7492 try {
7493 session = openSession();
7494
7495 Query q = session.createQuery(sql);
7496
7497 QueryPos qPos = QueryPos.getInstance(q);
7498
7499 qPos.add(groupId);
7500
7501 if (name != null) {
7502 qPos.add(name);
7503 }
7504
7505 if (vocabularyIds != null) {
7506 qPos.add(vocabularyIds);
7507 }
7508
7509 if (!pagination) {
7510 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7511 start, end, false);
7512
7513 Collections.sort(list);
7514
7515 list = new UnmodifiableList<AssetCategory>(list);
7516 }
7517 else {
7518 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7519 start, end);
7520 }
7521
7522 cacheResult(list);
7523
7524 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
7525 finderArgs, list);
7526 }
7527 catch (Exception e) {
7528 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
7529 finderArgs);
7530
7531 throw processException(e);
7532 }
7533 finally {
7534 closeSession(session);
7535 }
7536 }
7537
7538 return list;
7539 }
7540
7541
7549 public void removeByG_LikeN_V(long groupId, String name, long vocabularyId)
7550 throws SystemException {
7551 for (AssetCategory assetCategory : findByG_LikeN_V(groupId, name,
7552 vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7553 remove(assetCategory);
7554 }
7555 }
7556
7557
7566 public int countByG_LikeN_V(long groupId, String name, long vocabularyId)
7567 throws SystemException {
7568 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V;
7569
7570 Object[] finderArgs = new Object[] { groupId, name, vocabularyId };
7571
7572 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7573 this);
7574
7575 if (count == null) {
7576 StringBundler query = new StringBundler(4);
7577
7578 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
7579
7580 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7581
7582 boolean bindName = false;
7583
7584 if (name == null) {
7585 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7586 }
7587 else if (name.equals(StringPool.BLANK)) {
7588 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7589 }
7590 else {
7591 bindName = true;
7592
7593 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7594 }
7595
7596 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7597
7598 String sql = query.toString();
7599
7600 Session session = null;
7601
7602 try {
7603 session = openSession();
7604
7605 Query q = session.createQuery(sql);
7606
7607 QueryPos qPos = QueryPos.getInstance(q);
7608
7609 qPos.add(groupId);
7610
7611 if (bindName) {
7612 qPos.add(name);
7613 }
7614
7615 qPos.add(vocabularyId);
7616
7617 count = (Long)q.uniqueResult();
7618
7619 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7620 }
7621 catch (Exception e) {
7622 FinderCacheUtil.removeResult(finderPath, finderArgs);
7623
7624 throw processException(e);
7625 }
7626 finally {
7627 closeSession(session);
7628 }
7629 }
7630
7631 return count.intValue();
7632 }
7633
7634
7643 public int countByG_LikeN_V(long groupId, String name, long[] vocabularyIds)
7644 throws SystemException {
7645 Object[] finderArgs = new Object[] {
7646 groupId, name, StringUtil.merge(vocabularyIds)
7647 };
7648
7649 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
7650 finderArgs, this);
7651
7652 if (count == null) {
7653 StringBundler query = new StringBundler();
7654
7655 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
7656
7657 boolean conjunctionable = false;
7658
7659 if (conjunctionable) {
7660 query.append(WHERE_AND);
7661 }
7662
7663 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
7664
7665 conjunctionable = true;
7666
7667 if (conjunctionable) {
7668 query.append(WHERE_AND);
7669 }
7670
7671 if (name == null) {
7672 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
7673 }
7674 else if (name.equals(StringPool.BLANK)) {
7675 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
7676 }
7677 else {
7678 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
7679 }
7680
7681 conjunctionable = true;
7682
7683 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
7684 if (conjunctionable) {
7685 query.append(WHERE_AND);
7686 }
7687
7688 query.append(StringPool.OPEN_PARENTHESIS);
7689
7690 for (int i = 0; i < vocabularyIds.length; i++) {
7691 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
7692
7693 if ((i + 1) < vocabularyIds.length) {
7694 query.append(WHERE_OR);
7695 }
7696 }
7697
7698 query.append(StringPool.CLOSE_PARENTHESIS);
7699
7700 conjunctionable = true;
7701 }
7702
7703 String sql = query.toString();
7704
7705 Session session = null;
7706
7707 try {
7708 session = openSession();
7709
7710 Query q = session.createQuery(sql);
7711
7712 QueryPos qPos = QueryPos.getInstance(q);
7713
7714 qPos.add(groupId);
7715
7716 if (name != null) {
7717 qPos.add(name);
7718 }
7719
7720 if (vocabularyIds != null) {
7721 qPos.add(vocabularyIds);
7722 }
7723
7724 count = (Long)q.uniqueResult();
7725
7726 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
7727 finderArgs, count);
7728 }
7729 catch (Exception e) {
7730 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
7731 finderArgs);
7732
7733 throw processException(e);
7734 }
7735 finally {
7736 closeSession(session);
7737 }
7738 }
7739
7740 return count.intValue();
7741 }
7742
7743
7752 public int filterCountByG_LikeN_V(long groupId, String name,
7753 long vocabularyId) throws SystemException {
7754 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7755 return countByG_LikeN_V(groupId, name, vocabularyId);
7756 }
7757
7758 StringBundler query = new StringBundler(4);
7759
7760 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
7761
7762 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7763
7764 boolean bindName = false;
7765
7766 if (name == null) {
7767 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7768 }
7769 else if (name.equals(StringPool.BLANK)) {
7770 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7771 }
7772 else {
7773 bindName = true;
7774
7775 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7776 }
7777
7778 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7779
7780 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7781 AssetCategory.class.getName(),
7782 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7783
7784 Session session = null;
7785
7786 try {
7787 session = openSession();
7788
7789 SQLQuery q = session.createSQLQuery(sql);
7790
7791 q.addScalar(COUNT_COLUMN_NAME,
7792 com.liferay.portal.kernel.dao.orm.Type.LONG);
7793
7794 QueryPos qPos = QueryPos.getInstance(q);
7795
7796 qPos.add(groupId);
7797
7798 if (bindName) {
7799 qPos.add(name);
7800 }
7801
7802 qPos.add(vocabularyId);
7803
7804 Long count = (Long)q.uniqueResult();
7805
7806 return count.intValue();
7807 }
7808 catch (Exception e) {
7809 throw processException(e);
7810 }
7811 finally {
7812 closeSession(session);
7813 }
7814 }
7815
7816
7825 public int filterCountByG_LikeN_V(long groupId, String name,
7826 long[] vocabularyIds) throws SystemException {
7827 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7828 return countByG_LikeN_V(groupId, name, vocabularyIds);
7829 }
7830
7831 StringBundler query = new StringBundler();
7832
7833 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
7834
7835 boolean conjunctionable = false;
7836
7837 if (conjunctionable) {
7838 query.append(WHERE_AND);
7839 }
7840
7841 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
7842
7843 conjunctionable = true;
7844
7845 if (conjunctionable) {
7846 query.append(WHERE_AND);
7847 }
7848
7849 if (name == null) {
7850 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
7851 }
7852 else if (name.equals(StringPool.BLANK)) {
7853 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
7854 }
7855 else {
7856 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
7857 }
7858
7859 conjunctionable = true;
7860
7861 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
7862 if (conjunctionable) {
7863 query.append(WHERE_AND);
7864 }
7865
7866 query.append(StringPool.OPEN_PARENTHESIS);
7867
7868 for (int i = 0; i < vocabularyIds.length; i++) {
7869 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
7870
7871 if ((i + 1) < vocabularyIds.length) {
7872 query.append(WHERE_OR);
7873 }
7874 }
7875
7876 query.append(StringPool.CLOSE_PARENTHESIS);
7877
7878 conjunctionable = true;
7879 }
7880
7881 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7882 AssetCategory.class.getName(),
7883 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7884
7885 Session session = null;
7886
7887 try {
7888 session = openSession();
7889
7890 SQLQuery q = session.createSQLQuery(sql);
7891
7892 q.addScalar(COUNT_COLUMN_NAME,
7893 com.liferay.portal.kernel.dao.orm.Type.LONG);
7894
7895 QueryPos qPos = QueryPos.getInstance(q);
7896
7897 qPos.add(groupId);
7898
7899 if (name != null) {
7900 qPos.add(name);
7901 }
7902
7903 if (vocabularyIds != null) {
7904 qPos.add(vocabularyIds);
7905 }
7906
7907 Long count = (Long)q.uniqueResult();
7908
7909 return count.intValue();
7910 }
7911 catch (Exception e) {
7912 throw processException(e);
7913 }
7914 finally {
7915 closeSession(session);
7916 }
7917 }
7918
7919 private static final String _FINDER_COLUMN_G_LIKEN_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
7920 private static final String _FINDER_COLUMN_G_LIKEN_V_GROUPID_5 = "(" +
7921 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2) + ")";
7922 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_1 = "assetCategory.name LIKE NULL AND ";
7923 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_2 = "assetCategory.name LIKE ? AND ";
7924 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name LIKE '') AND ";
7925 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_4 = "(" +
7926 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_NAME_1) + ")";
7927 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_5 = "(" +
7928 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_NAME_2) + ")";
7929 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_6 = "(" +
7930 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_NAME_3) + ")";
7931 private static final String _FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
7932 private static final String _FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5 = "(" +
7933 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2) + ")";
7934 public static final FinderPath FINDER_PATH_FETCH_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7935 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
7936 AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByP_N_V",
7937 new String[] {
7938 Long.class.getName(), String.class.getName(),
7939 Long.class.getName()
7940 },
7941 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
7942 AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
7943 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
7944 public static final FinderPath FINDER_PATH_COUNT_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7945 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
7946 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N_V",
7947 new String[] {
7948 Long.class.getName(), String.class.getName(),
7949 Long.class.getName()
7950 });
7951
7952
7962 public AssetCategory findByP_N_V(long parentCategoryId, String name,
7963 long vocabularyId) throws NoSuchCategoryException, SystemException {
7964 AssetCategory assetCategory = fetchByP_N_V(parentCategoryId, name,
7965 vocabularyId);
7966
7967 if (assetCategory == null) {
7968 StringBundler msg = new StringBundler(8);
7969
7970 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7971
7972 msg.append("parentCategoryId=");
7973 msg.append(parentCategoryId);
7974
7975 msg.append(", name=");
7976 msg.append(name);
7977
7978 msg.append(", vocabularyId=");
7979 msg.append(vocabularyId);
7980
7981 msg.append(StringPool.CLOSE_CURLY_BRACE);
7982
7983 if (_log.isWarnEnabled()) {
7984 _log.warn(msg.toString());
7985 }
7986
7987 throw new NoSuchCategoryException(msg.toString());
7988 }
7989
7990 return assetCategory;
7991 }
7992
7993
8002 public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
8003 long vocabularyId) throws SystemException {
8004 return fetchByP_N_V(parentCategoryId, name, vocabularyId, true);
8005 }
8006
8007
8017 public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
8018 long vocabularyId, boolean retrieveFromCache) throws SystemException {
8019 Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
8020
8021 Object result = null;
8022
8023 if (retrieveFromCache) {
8024 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_N_V,
8025 finderArgs, this);
8026 }
8027
8028 if (result instanceof AssetCategory) {
8029 AssetCategory assetCategory = (AssetCategory)result;
8030
8031 if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
8032 !Validator.equals(name, assetCategory.getName()) ||
8033 (vocabularyId != assetCategory.getVocabularyId())) {
8034 result = null;
8035 }
8036 }
8037
8038 if (result == null) {
8039 StringBundler query = new StringBundler(5);
8040
8041 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
8042
8043 query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
8044
8045 boolean bindName = false;
8046
8047 if (name == null) {
8048 query.append(_FINDER_COLUMN_P_N_V_NAME_1);
8049 }
8050 else if (name.equals(StringPool.BLANK)) {
8051 query.append(_FINDER_COLUMN_P_N_V_NAME_3);
8052 }
8053 else {
8054 bindName = true;
8055
8056 query.append(_FINDER_COLUMN_P_N_V_NAME_2);
8057 }
8058
8059 query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
8060
8061 String sql = query.toString();
8062
8063 Session session = null;
8064
8065 try {
8066 session = openSession();
8067
8068 Query q = session.createQuery(sql);
8069
8070 QueryPos qPos = QueryPos.getInstance(q);
8071
8072 qPos.add(parentCategoryId);
8073
8074 if (bindName) {
8075 qPos.add(name);
8076 }
8077
8078 qPos.add(vocabularyId);
8079
8080 List<AssetCategory> list = q.list();
8081
8082 if (list.isEmpty()) {
8083 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
8084 finderArgs, list);
8085 }
8086 else {
8087 AssetCategory assetCategory = list.get(0);
8088
8089 result = assetCategory;
8090
8091 cacheResult(assetCategory);
8092
8093 if ((assetCategory.getParentCategoryId() != parentCategoryId) ||
8094 (assetCategory.getName() == null) ||
8095 !assetCategory.getName().equals(name) ||
8096 (assetCategory.getVocabularyId() != vocabularyId)) {
8097 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
8098 finderArgs, assetCategory);
8099 }
8100 }
8101 }
8102 catch (Exception e) {
8103 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V,
8104 finderArgs);
8105
8106 throw processException(e);
8107 }
8108 finally {
8109 closeSession(session);
8110 }
8111 }
8112
8113 if (result instanceof List<?>) {
8114 return null;
8115 }
8116 else {
8117 return (AssetCategory)result;
8118 }
8119 }
8120
8121
8130 public AssetCategory removeByP_N_V(long parentCategoryId, String name,
8131 long vocabularyId) throws NoSuchCategoryException, SystemException {
8132 AssetCategory assetCategory = findByP_N_V(parentCategoryId, name,
8133 vocabularyId);
8134
8135 return remove(assetCategory);
8136 }
8137
8138
8147 public int countByP_N_V(long parentCategoryId, String name,
8148 long vocabularyId) throws SystemException {
8149 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N_V;
8150
8151 Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
8152
8153 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8154 this);
8155
8156 if (count == null) {
8157 StringBundler query = new StringBundler(4);
8158
8159 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
8160
8161 query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
8162
8163 boolean bindName = false;
8164
8165 if (name == null) {
8166 query.append(_FINDER_COLUMN_P_N_V_NAME_1);
8167 }
8168 else if (name.equals(StringPool.BLANK)) {
8169 query.append(_FINDER_COLUMN_P_N_V_NAME_3);
8170 }
8171 else {
8172 bindName = true;
8173
8174 query.append(_FINDER_COLUMN_P_N_V_NAME_2);
8175 }
8176
8177 query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
8178
8179 String sql = query.toString();
8180
8181 Session session = null;
8182
8183 try {
8184 session = openSession();
8185
8186 Query q = session.createQuery(sql);
8187
8188 QueryPos qPos = QueryPos.getInstance(q);
8189
8190 qPos.add(parentCategoryId);
8191
8192 if (bindName) {
8193 qPos.add(name);
8194 }
8195
8196 qPos.add(vocabularyId);
8197
8198 count = (Long)q.uniqueResult();
8199
8200 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8201 }
8202 catch (Exception e) {
8203 FinderCacheUtil.removeResult(finderPath, finderArgs);
8204
8205 throw processException(e);
8206 }
8207 finally {
8208 closeSession(session);
8209 }
8210 }
8211
8212 return count.intValue();
8213 }
8214
8215 private static final String _FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
8216 private static final String _FINDER_COLUMN_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
8217 private static final String _FINDER_COLUMN_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
8218 private static final String _FINDER_COLUMN_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
8219 private static final String _FINDER_COLUMN_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
8220 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
8221 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
8222 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
8223 "findByG_P_N_V",
8224 new String[] {
8225 Long.class.getName(), Long.class.getName(),
8226 String.class.getName(), Long.class.getName(),
8227
8228 Integer.class.getName(), Integer.class.getName(),
8229 OrderByComparator.class.getName()
8230 });
8231 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V =
8232 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
8233 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
8234 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
8235 "findByG_P_N_V",
8236 new String[] {
8237 Long.class.getName(), Long.class.getName(),
8238 String.class.getName(), Long.class.getName()
8239 },
8240 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
8241 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
8242 AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
8243 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
8244 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
8245 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
8246 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N_V",
8247 new String[] {
8248 Long.class.getName(), Long.class.getName(),
8249 String.class.getName(), Long.class.getName()
8250 });
8251
8252
8262 public List<AssetCategory> findByG_P_N_V(long groupId,
8263 long parentCategoryId, String name, long vocabularyId)
8264 throws SystemException {
8265 return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
8266 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8267 }
8268
8269
8285 public List<AssetCategory> findByG_P_N_V(long groupId,
8286 long parentCategoryId, String name, long vocabularyId, int start,
8287 int end) throws SystemException {
8288 return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
8289 start, end, null);
8290 }
8291
8292
8309 public List<AssetCategory> findByG_P_N_V(long groupId,
8310 long parentCategoryId, String name, long vocabularyId, int start,
8311 int end, OrderByComparator orderByComparator) throws SystemException {
8312 boolean pagination = true;
8313 FinderPath finderPath = null;
8314 Object[] finderArgs = null;
8315
8316 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8317 (orderByComparator == null)) {
8318 pagination = false;
8319 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V;
8320 finderArgs = new Object[] {
8321 groupId, parentCategoryId, name, vocabularyId
8322 };
8323 }
8324 else {
8325 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V;
8326 finderArgs = new Object[] {
8327 groupId, parentCategoryId, name, vocabularyId,
8328
8329 start, end, orderByComparator
8330 };
8331 }
8332
8333 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
8334 finderArgs, this);
8335
8336 if ((list != null) && !list.isEmpty()) {
8337 for (AssetCategory assetCategory : list) {
8338 if ((groupId != assetCategory.getGroupId()) ||
8339 (parentCategoryId != assetCategory.getParentCategoryId()) ||
8340 !Validator.equals(name, assetCategory.getName()) ||
8341 (vocabularyId != assetCategory.getVocabularyId())) {
8342 list = null;
8343
8344 break;
8345 }
8346 }
8347 }
8348
8349 if (list == null) {
8350 StringBundler query = null;
8351
8352 if (orderByComparator != null) {
8353 query = new StringBundler(6 +
8354 (orderByComparator.getOrderByFields().length * 3));
8355 }
8356 else {
8357 query = new StringBundler(6);
8358 }
8359
8360 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
8361
8362 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
8363
8364 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
8365
8366 boolean bindName = false;
8367
8368 if (name == null) {
8369 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
8370 }
8371 else if (name.equals(StringPool.BLANK)) {
8372 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
8373 }
8374 else {
8375 bindName = true;
8376
8377 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
8378 }
8379
8380 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
8381
8382 if (orderByComparator != null) {
8383 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8384 orderByComparator);
8385 }
8386 else
8387 if (pagination) {
8388 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8389 }
8390
8391 String sql = query.toString();
8392
8393 Session session = null;
8394
8395 try {
8396 session = openSession();
8397
8398 Query q = session.createQuery(sql);
8399
8400 QueryPos qPos = QueryPos.getInstance(q);
8401
8402 qPos.add(groupId);
8403
8404 qPos.add(parentCategoryId);
8405
8406 if (bindName) {
8407 qPos.add(name);
8408 }
8409
8410 qPos.add(vocabularyId);
8411
8412 if (!pagination) {
8413 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
8414 start, end, false);
8415
8416 Collections.sort(list);
8417
8418 list = new UnmodifiableList<AssetCategory>(list);
8419 }
8420 else {
8421 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
8422 start, end);
8423 }
8424
8425 cacheResult(list);
8426
8427 FinderCacheUtil.putResult(finderPath, finderArgs, list);
8428 }
8429 catch (Exception e) {
8430 FinderCacheUtil.removeResult(finderPath, finderArgs);
8431
8432 throw processException(e);
8433 }
8434 finally {
8435 closeSession(session);
8436 }
8437 }
8438
8439 return list;
8440 }
8441
8442
8454 public AssetCategory findByG_P_N_V_First(long groupId,
8455 long parentCategoryId, String name, long vocabularyId,
8456 OrderByComparator orderByComparator)
8457 throws NoSuchCategoryException, SystemException {
8458 AssetCategory assetCategory = fetchByG_P_N_V_First(groupId,
8459 parentCategoryId, name, vocabularyId, orderByComparator);
8460
8461 if (assetCategory != null) {
8462 return assetCategory;
8463 }
8464
8465 StringBundler msg = new StringBundler(10);
8466
8467 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8468
8469 msg.append("groupId=");
8470 msg.append(groupId);
8471
8472 msg.append(", parentCategoryId=");
8473 msg.append(parentCategoryId);
8474
8475 msg.append(", name=");
8476 msg.append(name);
8477
8478 msg.append(", vocabularyId=");
8479 msg.append(vocabularyId);
8480
8481 msg.append(StringPool.CLOSE_CURLY_BRACE);
8482
8483 throw new NoSuchCategoryException(msg.toString());
8484 }
8485
8486
8497 public AssetCategory fetchByG_P_N_V_First(long groupId,
8498 long parentCategoryId, String name, long vocabularyId,
8499 OrderByComparator orderByComparator) throws SystemException {
8500 List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
8501 name, vocabularyId, 0, 1, orderByComparator);
8502
8503 if (!list.isEmpty()) {
8504 return list.get(0);
8505 }
8506
8507 return null;
8508 }
8509
8510
8522 public AssetCategory findByG_P_N_V_Last(long groupId,
8523 long parentCategoryId, String name, long vocabularyId,
8524 OrderByComparator orderByComparator)
8525 throws NoSuchCategoryException, SystemException {
8526 AssetCategory assetCategory = fetchByG_P_N_V_Last(groupId,
8527 parentCategoryId, name, vocabularyId, orderByComparator);
8528
8529 if (assetCategory != null) {
8530 return assetCategory;
8531 }
8532
8533 StringBundler msg = new StringBundler(10);
8534
8535 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8536
8537 msg.append("groupId=");
8538 msg.append(groupId);
8539
8540 msg.append(", parentCategoryId=");
8541 msg.append(parentCategoryId);
8542
8543 msg.append(", name=");
8544 msg.append(name);
8545
8546 msg.append(", vocabularyId=");
8547 msg.append(vocabularyId);
8548
8549 msg.append(StringPool.CLOSE_CURLY_BRACE);
8550
8551 throw new NoSuchCategoryException(msg.toString());
8552 }
8553
8554
8565 public AssetCategory fetchByG_P_N_V_Last(long groupId,
8566 long parentCategoryId, String name, long vocabularyId,
8567 OrderByComparator orderByComparator) throws SystemException {
8568 int count = countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
8569
8570 List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
8571 name, vocabularyId, count - 1, count, orderByComparator);
8572
8573 if (!list.isEmpty()) {
8574 return list.get(0);
8575 }
8576
8577 return null;
8578 }
8579
8580
8593 public AssetCategory[] findByG_P_N_V_PrevAndNext(long categoryId,
8594 long groupId, long parentCategoryId, String name, long vocabularyId,
8595 OrderByComparator orderByComparator)
8596 throws NoSuchCategoryException, SystemException {
8597 AssetCategory assetCategory = findByPrimaryKey(categoryId);
8598
8599 Session session = null;
8600
8601 try {
8602 session = openSession();
8603
8604 AssetCategory[] array = new AssetCategoryImpl[3];
8605
8606 array[0] = getByG_P_N_V_PrevAndNext(session, assetCategory,
8607 groupId, parentCategoryId, name, vocabularyId,
8608 orderByComparator, true);
8609
8610 array[1] = assetCategory;
8611
8612 array[2] = getByG_P_N_V_PrevAndNext(session, assetCategory,
8613 groupId, parentCategoryId, name, vocabularyId,
8614 orderByComparator, false);
8615
8616 return array;
8617 }
8618 catch (Exception e) {
8619 throw processException(e);
8620 }
8621 finally {
8622 closeSession(session);
8623 }
8624 }
8625
8626 protected AssetCategory getByG_P_N_V_PrevAndNext(Session session,
8627 AssetCategory assetCategory, long groupId, long parentCategoryId,
8628 String name, long vocabularyId, OrderByComparator orderByComparator,
8629 boolean previous) {
8630 StringBundler query = null;
8631
8632 if (orderByComparator != null) {
8633 query = new StringBundler(6 +
8634 (orderByComparator.getOrderByFields().length * 6));
8635 }
8636 else {
8637 query = new StringBundler(3);
8638 }
8639
8640 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
8641
8642 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
8643
8644 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
8645
8646 boolean bindName = false;
8647
8648 if (name == null) {
8649 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
8650 }
8651 else if (name.equals(StringPool.BLANK)) {
8652 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
8653 }
8654 else {
8655 bindName = true;
8656
8657 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
8658 }
8659
8660 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
8661
8662 if (orderByComparator != null) {
8663 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8664
8665 if (orderByConditionFields.length > 0) {
8666 query.append(WHERE_AND);
8667 }
8668
8669 for (int i = 0; i < orderByConditionFields.length; i++) {
8670 query.append(_ORDER_BY_ENTITY_ALIAS);
8671 query.append(orderByConditionFields[i]);
8672
8673 if ((i + 1) < orderByConditionFields.length) {
8674 if (orderByComparator.isAscending() ^ previous) {
8675 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8676 }
8677 else {
8678 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8679 }
8680 }
8681 else {
8682 if (orderByComparator.isAscending() ^ previous) {
8683 query.append(WHERE_GREATER_THAN);
8684 }
8685 else {
8686 query.append(WHERE_LESSER_THAN);
8687 }
8688 }
8689 }
8690
8691 query.append(ORDER_BY_CLAUSE);
8692
8693 String[] orderByFields = orderByComparator.getOrderByFields();
8694
8695 for (int i = 0; i < orderByFields.length; i++) {
8696 query.append(_ORDER_BY_ENTITY_ALIAS);
8697 query.append(orderByFields[i]);
8698
8699 if ((i + 1) < orderByFields.length) {
8700 if (orderByComparator.isAscending() ^ previous) {
8701 query.append(ORDER_BY_ASC_HAS_NEXT);
8702 }
8703 else {
8704 query.append(ORDER_BY_DESC_HAS_NEXT);
8705 }
8706 }
8707 else {
8708 if (orderByComparator.isAscending() ^ previous) {
8709 query.append(ORDER_BY_ASC);
8710 }
8711 else {
8712 query.append(ORDER_BY_DESC);
8713 }
8714 }
8715 }
8716 }
8717 else {
8718 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8719 }
8720
8721 String sql = query.toString();
8722
8723 Query q = session.createQuery(sql);
8724
8725 q.setFirstResult(0);
8726 q.setMaxResults(2);
8727
8728 QueryPos qPos = QueryPos.getInstance(q);
8729
8730 qPos.add(groupId);
8731
8732 qPos.add(parentCategoryId);
8733
8734 if (bindName) {
8735 qPos.add(name);
8736 }
8737
8738 qPos.add(vocabularyId);
8739
8740 if (orderByComparator != null) {
8741 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
8742
8743 for (Object value : values) {
8744 qPos.add(value);
8745 }
8746 }
8747
8748 List<AssetCategory> list = q.list();
8749
8750 if (list.size() == 2) {
8751 return list.get(1);
8752 }
8753 else {
8754 return null;
8755 }
8756 }
8757
8758
8768 public List<AssetCategory> filterFindByG_P_N_V(long groupId,
8769 long parentCategoryId, String name, long vocabularyId)
8770 throws SystemException {
8771 return filterFindByG_P_N_V(groupId, parentCategoryId, name,
8772 vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8773 }
8774
8775
8791 public List<AssetCategory> filterFindByG_P_N_V(long groupId,
8792 long parentCategoryId, String name, long vocabularyId, int start,
8793 int end) throws SystemException {
8794 return filterFindByG_P_N_V(groupId, parentCategoryId, name,
8795 vocabularyId, start, end, null);
8796 }
8797
8798
8815 public List<AssetCategory> filterFindByG_P_N_V(long groupId,
8816 long parentCategoryId, String name, long vocabularyId, int start,
8817 int end, OrderByComparator orderByComparator) throws SystemException {
8818 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8819 return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
8820 start, end, orderByComparator);
8821 }
8822
8823 StringBundler query = null;
8824
8825 if (orderByComparator != null) {
8826 query = new StringBundler(6 +
8827 (orderByComparator.getOrderByFields().length * 3));
8828 }
8829 else {
8830 query = new StringBundler(6);
8831 }
8832
8833 if (getDB().isSupportsInlineDistinct()) {
8834 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8835 }
8836 else {
8837 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8838 }
8839
8840 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
8841
8842 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
8843
8844 boolean bindName = false;
8845
8846 if (name == null) {
8847 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
8848 }
8849 else if (name.equals(StringPool.BLANK)) {
8850 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
8851 }
8852 else {
8853 bindName = true;
8854
8855 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
8856 }
8857
8858 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
8859
8860 if (!getDB().isSupportsInlineDistinct()) {
8861 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8862 }
8863
8864 if (orderByComparator != null) {
8865 if (getDB().isSupportsInlineDistinct()) {
8866 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8867 orderByComparator);
8868 }
8869 else {
8870 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8871 orderByComparator);
8872 }
8873 }
8874 else {
8875 if (getDB().isSupportsInlineDistinct()) {
8876 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8877 }
8878 else {
8879 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8880 }
8881 }
8882
8883 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8884 AssetCategory.class.getName(),
8885 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8886
8887 Session session = null;
8888
8889 try {
8890 session = openSession();
8891
8892 SQLQuery q = session.createSQLQuery(sql);
8893
8894 if (getDB().isSupportsInlineDistinct()) {
8895 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8896 }
8897 else {
8898 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8899 }
8900
8901 QueryPos qPos = QueryPos.getInstance(q);
8902
8903 qPos.add(groupId);
8904
8905 qPos.add(parentCategoryId);
8906
8907 if (bindName) {
8908 qPos.add(name);
8909 }
8910
8911 qPos.add(vocabularyId);
8912
8913 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
8914 end);
8915 }
8916 catch (Exception e) {
8917 throw processException(e);
8918 }
8919 finally {
8920 closeSession(session);
8921 }
8922 }
8923
8924
8937 public AssetCategory[] filterFindByG_P_N_V_PrevAndNext(long categoryId,
8938 long groupId, long parentCategoryId, String name, long vocabularyId,
8939 OrderByComparator orderByComparator)
8940 throws NoSuchCategoryException, SystemException {
8941 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8942 return findByG_P_N_V_PrevAndNext(categoryId, groupId,
8943 parentCategoryId, name, vocabularyId, orderByComparator);
8944 }
8945
8946 AssetCategory assetCategory = findByPrimaryKey(categoryId);
8947
8948 Session session = null;
8949
8950 try {
8951 session = openSession();
8952
8953 AssetCategory[] array = new AssetCategoryImpl[3];
8954
8955 array[0] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
8956 groupId, parentCategoryId, name, vocabularyId,
8957 orderByComparator, true);
8958
8959 array[1] = assetCategory;
8960
8961 array[2] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
8962 groupId, parentCategoryId, name, vocabularyId,
8963 orderByComparator, false);
8964
8965 return array;
8966 }
8967 catch (Exception e) {
8968 throw processException(e);
8969 }
8970 finally {
8971 closeSession(session);
8972 }
8973 }
8974
8975 protected AssetCategory filterGetByG_P_N_V_PrevAndNext(Session session,
8976 AssetCategory assetCategory, long groupId, long parentCategoryId,
8977 String name, long vocabularyId, OrderByComparator orderByComparator,
8978 boolean previous) {
8979 StringBundler query = null;
8980
8981 if (orderByComparator != null) {
8982 query = new StringBundler(6 +
8983 (orderByComparator.getOrderByFields().length * 6));
8984 }
8985 else {
8986 query = new StringBundler(3);
8987 }
8988
8989 if (getDB().isSupportsInlineDistinct()) {
8990 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8991 }
8992 else {
8993 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8994 }
8995
8996 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
8997
8998 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
8999
9000 boolean bindName = false;
9001
9002 if (name == null) {
9003 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9004 }
9005 else if (name.equals(StringPool.BLANK)) {
9006 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9007 }
9008 else {
9009 bindName = true;
9010
9011 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9012 }
9013
9014 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9015
9016 if (!getDB().isSupportsInlineDistinct()) {
9017 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
9018 }
9019
9020 if (orderByComparator != null) {
9021 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9022
9023 if (orderByConditionFields.length > 0) {
9024 query.append(WHERE_AND);
9025 }
9026
9027 for (int i = 0; i < orderByConditionFields.length; i++) {
9028 if (getDB().isSupportsInlineDistinct()) {
9029 query.append(_ORDER_BY_ENTITY_ALIAS);
9030 }
9031 else {
9032 query.append(_ORDER_BY_ENTITY_TABLE);
9033 }
9034
9035 query.append(orderByConditionFields[i]);
9036
9037 if ((i + 1) < orderByConditionFields.length) {
9038 if (orderByComparator.isAscending() ^ previous) {
9039 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9040 }
9041 else {
9042 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9043 }
9044 }
9045 else {
9046 if (orderByComparator.isAscending() ^ previous) {
9047 query.append(WHERE_GREATER_THAN);
9048 }
9049 else {
9050 query.append(WHERE_LESSER_THAN);
9051 }
9052 }
9053 }
9054
9055 query.append(ORDER_BY_CLAUSE);
9056
9057 String[] orderByFields = orderByComparator.getOrderByFields();
9058
9059 for (int i = 0; i < orderByFields.length; i++) {
9060 if (getDB().isSupportsInlineDistinct()) {
9061 query.append(_ORDER_BY_ENTITY_ALIAS);
9062 }
9063 else {
9064 query.append(_ORDER_BY_ENTITY_TABLE);
9065 }
9066
9067 query.append(orderByFields[i]);
9068
9069 if ((i + 1) < orderByFields.length) {
9070 if (orderByComparator.isAscending() ^ previous) {
9071 query.append(ORDER_BY_ASC_HAS_NEXT);
9072 }
9073 else {
9074 query.append(ORDER_BY_DESC_HAS_NEXT);
9075 }
9076 }
9077 else {
9078 if (orderByComparator.isAscending() ^ previous) {
9079 query.append(ORDER_BY_ASC);
9080 }
9081 else {
9082 query.append(ORDER_BY_DESC);
9083 }
9084 }
9085 }
9086 }
9087 else {
9088 if (getDB().isSupportsInlineDistinct()) {
9089 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
9090 }
9091 else {
9092 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
9093 }
9094 }
9095
9096 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9097 AssetCategory.class.getName(),
9098 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9099
9100 SQLQuery q = session.createSQLQuery(sql);
9101
9102 q.setFirstResult(0);
9103 q.setMaxResults(2);
9104
9105 if (getDB().isSupportsInlineDistinct()) {
9106 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
9107 }
9108 else {
9109 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
9110 }
9111
9112 QueryPos qPos = QueryPos.getInstance(q);
9113
9114 qPos.add(groupId);
9115
9116 qPos.add(parentCategoryId);
9117
9118 if (bindName) {
9119 qPos.add(name);
9120 }
9121
9122 qPos.add(vocabularyId);
9123
9124 if (orderByComparator != null) {
9125 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
9126
9127 for (Object value : values) {
9128 qPos.add(value);
9129 }
9130 }
9131
9132 List<AssetCategory> list = q.list();
9133
9134 if (list.size() == 2) {
9135 return list.get(1);
9136 }
9137 else {
9138 return null;
9139 }
9140 }
9141
9142
9151 public void removeByG_P_N_V(long groupId, long parentCategoryId,
9152 String name, long vocabularyId) throws SystemException {
9153 for (AssetCategory assetCategory : findByG_P_N_V(groupId,
9154 parentCategoryId, name, vocabularyId, QueryUtil.ALL_POS,
9155 QueryUtil.ALL_POS, null)) {
9156 remove(assetCategory);
9157 }
9158 }
9159
9160
9170 public int countByG_P_N_V(long groupId, long parentCategoryId, String name,
9171 long vocabularyId) throws SystemException {
9172 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N_V;
9173
9174 Object[] finderArgs = new Object[] {
9175 groupId, parentCategoryId, name, vocabularyId
9176 };
9177
9178 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9179 this);
9180
9181 if (count == null) {
9182 StringBundler query = new StringBundler(5);
9183
9184 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
9185
9186 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
9187
9188 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
9189
9190 boolean bindName = false;
9191
9192 if (name == null) {
9193 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9194 }
9195 else if (name.equals(StringPool.BLANK)) {
9196 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9197 }
9198 else {
9199 bindName = true;
9200
9201 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9202 }
9203
9204 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9205
9206 String sql = query.toString();
9207
9208 Session session = null;
9209
9210 try {
9211 session = openSession();
9212
9213 Query q = session.createQuery(sql);
9214
9215 QueryPos qPos = QueryPos.getInstance(q);
9216
9217 qPos.add(groupId);
9218
9219 qPos.add(parentCategoryId);
9220
9221 if (bindName) {
9222 qPos.add(name);
9223 }
9224
9225 qPos.add(vocabularyId);
9226
9227 count = (Long)q.uniqueResult();
9228
9229 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9230 }
9231 catch (Exception e) {
9232 FinderCacheUtil.removeResult(finderPath, finderArgs);
9233
9234 throw processException(e);
9235 }
9236 finally {
9237 closeSession(session);
9238 }
9239 }
9240
9241 return count.intValue();
9242 }
9243
9244
9254 public int filterCountByG_P_N_V(long groupId, long parentCategoryId,
9255 String name, long vocabularyId) throws SystemException {
9256 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9257 return countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
9258 }
9259
9260 StringBundler query = new StringBundler(5);
9261
9262 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
9263
9264 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
9265
9266 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
9267
9268 boolean bindName = false;
9269
9270 if (name == null) {
9271 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9272 }
9273 else if (name.equals(StringPool.BLANK)) {
9274 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9275 }
9276 else {
9277 bindName = true;
9278
9279 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9280 }
9281
9282 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9283
9284 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9285 AssetCategory.class.getName(),
9286 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9287
9288 Session session = null;
9289
9290 try {
9291 session = openSession();
9292
9293 SQLQuery q = session.createSQLQuery(sql);
9294
9295 q.addScalar(COUNT_COLUMN_NAME,
9296 com.liferay.portal.kernel.dao.orm.Type.LONG);
9297
9298 QueryPos qPos = QueryPos.getInstance(q);
9299
9300 qPos.add(groupId);
9301
9302 qPos.add(parentCategoryId);
9303
9304 if (bindName) {
9305 qPos.add(name);
9306 }
9307
9308 qPos.add(vocabularyId);
9309
9310 Long count = (Long)q.uniqueResult();
9311
9312 return count.intValue();
9313 }
9314 catch (Exception e) {
9315 throw processException(e);
9316 }
9317 finally {
9318 closeSession(session);
9319 }
9320 }
9321
9322 private static final String _FINDER_COLUMN_G_P_N_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
9323 private static final String _FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
9324 private static final String _FINDER_COLUMN_G_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
9325 private static final String _FINDER_COLUMN_G_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
9326 private static final String _FINDER_COLUMN_G_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
9327 private static final String _FINDER_COLUMN_G_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
9328
9329
9334 public void cacheResult(AssetCategory assetCategory) {
9335 EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9336 AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
9337 assetCategory);
9338
9339 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
9340 new Object[] { assetCategory.getUuid(), assetCategory.getGroupId() },
9341 assetCategory);
9342
9343 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
9344 new Object[] {
9345 assetCategory.getParentCategoryId(), assetCategory.getName(),
9346 assetCategory.getVocabularyId()
9347 }, assetCategory);
9348
9349 assetCategory.resetOriginalValues();
9350 }
9351
9352
9357 public void cacheResult(List<AssetCategory> assetCategories) {
9358 for (AssetCategory assetCategory : assetCategories) {
9359 if (EntityCacheUtil.getResult(
9360 AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9361 AssetCategoryImpl.class, assetCategory.getPrimaryKey()) == null) {
9362 cacheResult(assetCategory);
9363 }
9364 else {
9365 assetCategory.resetOriginalValues();
9366 }
9367 }
9368 }
9369
9370
9377 @Override
9378 public void clearCache() {
9379 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
9380 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
9381 }
9382
9383 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
9384
9385 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
9386 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9387 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9388 }
9389
9390
9397 @Override
9398 public void clearCache(AssetCategory assetCategory) {
9399 EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9400 AssetCategoryImpl.class, assetCategory.getPrimaryKey());
9401
9402 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9403 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9404
9405 clearUniqueFindersCache(assetCategory);
9406 }
9407
9408 @Override
9409 public void clearCache(List<AssetCategory> assetCategories) {
9410 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9411 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9412
9413 for (AssetCategory assetCategory : assetCategories) {
9414 EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9415 AssetCategoryImpl.class, assetCategory.getPrimaryKey());
9416
9417 clearUniqueFindersCache(assetCategory);
9418 }
9419 }
9420
9421 protected void cacheUniqueFindersCache(AssetCategory assetCategory) {
9422 if (assetCategory.isNew()) {
9423 Object[] args = new Object[] {
9424 assetCategory.getUuid(), assetCategory.getGroupId()
9425 };
9426
9427 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9428 Long.valueOf(1));
9429 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9430 assetCategory);
9431
9432 args = new Object[] {
9433 assetCategory.getParentCategoryId(), assetCategory.getName(),
9434 assetCategory.getVocabularyId()
9435 };
9436
9437 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
9438 Long.valueOf(1));
9439 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
9440 assetCategory);
9441 }
9442 else {
9443 AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
9444
9445 if ((assetCategoryModelImpl.getColumnBitmask() &
9446 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9447 Object[] args = new Object[] {
9448 assetCategory.getUuid(), assetCategory.getGroupId()
9449 };
9450
9451 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9452 Long.valueOf(1));
9453 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9454 assetCategory);
9455 }
9456
9457 if ((assetCategoryModelImpl.getColumnBitmask() &
9458 FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
9459 Object[] args = new Object[] {
9460 assetCategory.getParentCategoryId(),
9461 assetCategory.getName(), assetCategory.getVocabularyId()
9462 };
9463
9464 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
9465 Long.valueOf(1));
9466 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
9467 assetCategory);
9468 }
9469 }
9470 }
9471
9472 protected void clearUniqueFindersCache(AssetCategory assetCategory) {
9473 AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
9474
9475 Object[] args = new Object[] {
9476 assetCategory.getUuid(), assetCategory.getGroupId()
9477 };
9478
9479 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9480 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9481
9482 if ((assetCategoryModelImpl.getColumnBitmask() &
9483 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9484 args = new Object[] {
9485 assetCategoryModelImpl.getOriginalUuid(),
9486 assetCategoryModelImpl.getOriginalGroupId()
9487 };
9488
9489 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9490 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9491 }
9492
9493 args = new Object[] {
9494 assetCategory.getParentCategoryId(), assetCategory.getName(),
9495 assetCategory.getVocabularyId()
9496 };
9497
9498 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
9499 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
9500
9501 if ((assetCategoryModelImpl.getColumnBitmask() &
9502 FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
9503 args = new Object[] {
9504 assetCategoryModelImpl.getOriginalParentCategoryId(),
9505 assetCategoryModelImpl.getOriginalName(),
9506 assetCategoryModelImpl.getOriginalVocabularyId()
9507 };
9508
9509 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
9510 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
9511 }
9512 }
9513
9514
9520 public AssetCategory create(long categoryId) {
9521 AssetCategory assetCategory = new AssetCategoryImpl();
9522
9523 assetCategory.setNew(true);
9524 assetCategory.setPrimaryKey(categoryId);
9525
9526 String uuid = PortalUUIDUtil.generate();
9527
9528 assetCategory.setUuid(uuid);
9529
9530 return assetCategory;
9531 }
9532
9533
9541 public AssetCategory remove(long categoryId)
9542 throws NoSuchCategoryException, SystemException {
9543 return remove((Serializable)categoryId);
9544 }
9545
9546
9554 @Override
9555 public AssetCategory remove(Serializable primaryKey)
9556 throws NoSuchCategoryException, SystemException {
9557 Session session = null;
9558
9559 try {
9560 session = openSession();
9561
9562 AssetCategory assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
9563 primaryKey);
9564
9565 if (assetCategory == null) {
9566 if (_log.isWarnEnabled()) {
9567 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9568 }
9569
9570 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9571 primaryKey);
9572 }
9573
9574 return remove(assetCategory);
9575 }
9576 catch (NoSuchCategoryException nsee) {
9577 throw nsee;
9578 }
9579 catch (Exception e) {
9580 throw processException(e);
9581 }
9582 finally {
9583 closeSession(session);
9584 }
9585 }
9586
9587 @Override
9588 protected AssetCategory removeImpl(AssetCategory assetCategory)
9589 throws SystemException {
9590 assetCategory = toUnwrappedModel(assetCategory);
9591
9592 try {
9593 clearAssetEntries.clear(assetCategory.getPrimaryKey());
9594 }
9595 catch (Exception e) {
9596 throw processException(e);
9597 }
9598 finally {
9599 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
9600 }
9601
9602 shrinkTree(assetCategory);
9603
9604 Session session = null;
9605
9606 try {
9607 session = openSession();
9608
9609 if (!session.contains(assetCategory)) {
9610 assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
9611 assetCategory.getPrimaryKeyObj());
9612 }
9613
9614 if (assetCategory != null) {
9615 session.delete(assetCategory);
9616 }
9617 }
9618 catch (Exception e) {
9619 throw processException(e);
9620 }
9621 finally {
9622 closeSession(session);
9623 }
9624
9625 if (assetCategory != null) {
9626 clearCache(assetCategory);
9627 }
9628
9629 return assetCategory;
9630 }
9631
9632 @Override
9633 public AssetCategory updateImpl(
9634 com.liferay.portlet.asset.model.AssetCategory assetCategory)
9635 throws SystemException {
9636 assetCategory = toUnwrappedModel(assetCategory);
9637
9638 boolean isNew = assetCategory.isNew();
9639
9640 AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
9641
9642 if (Validator.isNull(assetCategory.getUuid())) {
9643 String uuid = PortalUUIDUtil.generate();
9644
9645 assetCategory.setUuid(uuid);
9646 }
9647
9648 if (isNew) {
9649 expandTree(assetCategory, null);
9650 }
9651 else {
9652 if (assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) {
9653 List<Long> childrenCategoryIds = getChildrenTreeCategoryIds(assetCategory);
9654
9655 shrinkTree(assetCategory);
9656 expandTree(assetCategory, childrenCategoryIds);
9657 }
9658 }
9659
9660 Session session = null;
9661
9662 try {
9663 session = openSession();
9664
9665 if (assetCategory.isNew()) {
9666 session.save(assetCategory);
9667
9668 assetCategory.setNew(false);
9669 }
9670 else {
9671 session.merge(assetCategory);
9672 }
9673 }
9674 catch (Exception e) {
9675 throw processException(e);
9676 }
9677 finally {
9678 closeSession(session);
9679 }
9680
9681 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9682
9683 if (isNew || !AssetCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
9684 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9685 }
9686
9687 else {
9688 if ((assetCategoryModelImpl.getColumnBitmask() &
9689 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
9690 Object[] args = new Object[] {
9691 assetCategoryModelImpl.getOriginalUuid()
9692 };
9693
9694 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
9695 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
9696 args);
9697
9698 args = new Object[] { assetCategoryModelImpl.getUuid() };
9699
9700 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
9701 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
9702 args);
9703 }
9704
9705 if ((assetCategoryModelImpl.getColumnBitmask() &
9706 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
9707 Object[] args = new Object[] {
9708 assetCategoryModelImpl.getOriginalUuid(),
9709 assetCategoryModelImpl.getOriginalCompanyId()
9710 };
9711
9712 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9713 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9714 args);
9715
9716 args = new Object[] {
9717 assetCategoryModelImpl.getUuid(),
9718 assetCategoryModelImpl.getCompanyId()
9719 };
9720
9721 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9722 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9723 args);
9724 }
9725
9726 if ((assetCategoryModelImpl.getColumnBitmask() &
9727 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
9728 Object[] args = new Object[] {
9729 assetCategoryModelImpl.getOriginalGroupId()
9730 };
9731
9732 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9733 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9734 args);
9735
9736 args = new Object[] { assetCategoryModelImpl.getGroupId() };
9737
9738 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9739 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9740 args);
9741 }
9742
9743 if ((assetCategoryModelImpl.getColumnBitmask() &
9744 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID.getColumnBitmask()) != 0) {
9745 Object[] args = new Object[] {
9746 assetCategoryModelImpl.getOriginalParentCategoryId()
9747 };
9748
9749 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
9750 args);
9751 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
9752 args);
9753
9754 args = new Object[] { assetCategoryModelImpl.getParentCategoryId() };
9755
9756 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
9757 args);
9758 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
9759 args);
9760 }
9761
9762 if ((assetCategoryModelImpl.getColumnBitmask() &
9763 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID.getColumnBitmask()) != 0) {
9764 Object[] args = new Object[] {
9765 assetCategoryModelImpl.getOriginalVocabularyId()
9766 };
9767
9768 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
9769 args);
9770 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
9771 args);
9772
9773 args = new Object[] { assetCategoryModelImpl.getVocabularyId() };
9774
9775 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
9776 args);
9777 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
9778 args);
9779 }
9780
9781 if ((assetCategoryModelImpl.getColumnBitmask() &
9782 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V.getColumnBitmask()) != 0) {
9783 Object[] args = new Object[] {
9784 assetCategoryModelImpl.getOriginalGroupId(),
9785 assetCategoryModelImpl.getOriginalVocabularyId()
9786 };
9787
9788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
9789 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
9790 args);
9791
9792 args = new Object[] {
9793 assetCategoryModelImpl.getGroupId(),
9794 assetCategoryModelImpl.getVocabularyId()
9795 };
9796
9797 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
9798 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
9799 args);
9800 }
9801
9802 if ((assetCategoryModelImpl.getColumnBitmask() &
9803 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
9804 Object[] args = new Object[] {
9805 assetCategoryModelImpl.getOriginalParentCategoryId(),
9806 assetCategoryModelImpl.getOriginalName()
9807 };
9808
9809 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
9810 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
9811 args);
9812
9813 args = new Object[] {
9814 assetCategoryModelImpl.getParentCategoryId(),
9815 assetCategoryModelImpl.getName()
9816 };
9817
9818 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
9819 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
9820 args);
9821 }
9822
9823 if ((assetCategoryModelImpl.getColumnBitmask() &
9824 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V.getColumnBitmask()) != 0) {
9825 Object[] args = new Object[] {
9826 assetCategoryModelImpl.getOriginalParentCategoryId(),
9827 assetCategoryModelImpl.getOriginalVocabularyId()
9828 };
9829
9830 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
9831 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
9832 args);
9833
9834 args = new Object[] {
9835 assetCategoryModelImpl.getParentCategoryId(),
9836 assetCategoryModelImpl.getVocabularyId()
9837 };
9838
9839 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
9840 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
9841 args);
9842 }
9843
9844 if ((assetCategoryModelImpl.getColumnBitmask() &
9845 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V.getColumnBitmask()) != 0) {
9846 Object[] args = new Object[] {
9847 assetCategoryModelImpl.getOriginalName(),
9848 assetCategoryModelImpl.getOriginalVocabularyId()
9849 };
9850
9851 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
9852 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
9853 args);
9854
9855 args = new Object[] {
9856 assetCategoryModelImpl.getName(),
9857 assetCategoryModelImpl.getVocabularyId()
9858 };
9859
9860 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
9861 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
9862 args);
9863 }
9864
9865 if ((assetCategoryModelImpl.getColumnBitmask() &
9866 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V.getColumnBitmask()) != 0) {
9867 Object[] args = new Object[] {
9868 assetCategoryModelImpl.getOriginalGroupId(),
9869 assetCategoryModelImpl.getOriginalParentCategoryId(),
9870 assetCategoryModelImpl.getOriginalName(),
9871 assetCategoryModelImpl.getOriginalVocabularyId()
9872 };
9873
9874 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
9875 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
9876 args);
9877
9878 args = new Object[] {
9879 assetCategoryModelImpl.getGroupId(),
9880 assetCategoryModelImpl.getParentCategoryId(),
9881 assetCategoryModelImpl.getName(),
9882 assetCategoryModelImpl.getVocabularyId()
9883 };
9884
9885 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
9886 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
9887 args);
9888 }
9889 }
9890
9891 EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9892 AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
9893 assetCategory);
9894
9895 clearUniqueFindersCache(assetCategory);
9896 cacheUniqueFindersCache(assetCategory);
9897
9898 return assetCategory;
9899 }
9900
9901 protected AssetCategory toUnwrappedModel(AssetCategory assetCategory) {
9902 if (assetCategory instanceof AssetCategoryImpl) {
9903 return assetCategory;
9904 }
9905
9906 AssetCategoryImpl assetCategoryImpl = new AssetCategoryImpl();
9907
9908 assetCategoryImpl.setNew(assetCategory.isNew());
9909 assetCategoryImpl.setPrimaryKey(assetCategory.getPrimaryKey());
9910
9911 assetCategoryImpl.setUuid(assetCategory.getUuid());
9912 assetCategoryImpl.setCategoryId(assetCategory.getCategoryId());
9913 assetCategoryImpl.setGroupId(assetCategory.getGroupId());
9914 assetCategoryImpl.setCompanyId(assetCategory.getCompanyId());
9915 assetCategoryImpl.setUserId(assetCategory.getUserId());
9916 assetCategoryImpl.setUserName(assetCategory.getUserName());
9917 assetCategoryImpl.setCreateDate(assetCategory.getCreateDate());
9918 assetCategoryImpl.setModifiedDate(assetCategory.getModifiedDate());
9919 assetCategoryImpl.setParentCategoryId(assetCategory.getParentCategoryId());
9920 assetCategoryImpl.setLeftCategoryId(assetCategory.getLeftCategoryId());
9921 assetCategoryImpl.setRightCategoryId(assetCategory.getRightCategoryId());
9922 assetCategoryImpl.setName(assetCategory.getName());
9923 assetCategoryImpl.setTitle(assetCategory.getTitle());
9924 assetCategoryImpl.setDescription(assetCategory.getDescription());
9925 assetCategoryImpl.setVocabularyId(assetCategory.getVocabularyId());
9926
9927 return assetCategoryImpl;
9928 }
9929
9930
9938 @Override
9939 public AssetCategory findByPrimaryKey(Serializable primaryKey)
9940 throws NoSuchCategoryException, SystemException {
9941 AssetCategory assetCategory = fetchByPrimaryKey(primaryKey);
9942
9943 if (assetCategory == null) {
9944 if (_log.isWarnEnabled()) {
9945 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9946 }
9947
9948 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9949 primaryKey);
9950 }
9951
9952 return assetCategory;
9953 }
9954
9955
9963 public AssetCategory findByPrimaryKey(long categoryId)
9964 throws NoSuchCategoryException, SystemException {
9965 return findByPrimaryKey((Serializable)categoryId);
9966 }
9967
9968
9975 @Override
9976 public AssetCategory fetchByPrimaryKey(Serializable primaryKey)
9977 throws SystemException {
9978 AssetCategory assetCategory = (AssetCategory)EntityCacheUtil.getResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9979 AssetCategoryImpl.class, primaryKey);
9980
9981 if (assetCategory == _nullAssetCategory) {
9982 return null;
9983 }
9984
9985 if (assetCategory == null) {
9986 Session session = null;
9987
9988 try {
9989 session = openSession();
9990
9991 assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
9992 primaryKey);
9993
9994 if (assetCategory != null) {
9995 cacheResult(assetCategory);
9996 }
9997 else {
9998 EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9999 AssetCategoryImpl.class, primaryKey, _nullAssetCategory);
10000 }
10001 }
10002 catch (Exception e) {
10003 EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10004 AssetCategoryImpl.class, primaryKey);
10005
10006 throw processException(e);
10007 }
10008 finally {
10009 closeSession(session);
10010 }
10011 }
10012
10013 return assetCategory;
10014 }
10015
10016
10023 public AssetCategory fetchByPrimaryKey(long categoryId)
10024 throws SystemException {
10025 return fetchByPrimaryKey((Serializable)categoryId);
10026 }
10027
10028
10034 public List<AssetCategory> findAll() throws SystemException {
10035 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10036 }
10037
10038
10050 public List<AssetCategory> findAll(int start, int end)
10051 throws SystemException {
10052 return findAll(start, end, null);
10053 }
10054
10055
10068 public List<AssetCategory> findAll(int start, int end,
10069 OrderByComparator orderByComparator) throws SystemException {
10070 boolean pagination = true;
10071 FinderPath finderPath = null;
10072 Object[] finderArgs = null;
10073
10074 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10075 (orderByComparator == null)) {
10076 pagination = false;
10077 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
10078 finderArgs = FINDER_ARGS_EMPTY;
10079 }
10080 else {
10081 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
10082 finderArgs = new Object[] { start, end, orderByComparator };
10083 }
10084
10085 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
10086 finderArgs, this);
10087
10088 if (list == null) {
10089 StringBundler query = null;
10090 String sql = null;
10091
10092 if (orderByComparator != null) {
10093 query = new StringBundler(2 +
10094 (orderByComparator.getOrderByFields().length * 3));
10095
10096 query.append(_SQL_SELECT_ASSETCATEGORY);
10097
10098 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10099 orderByComparator);
10100
10101 sql = query.toString();
10102 }
10103 else {
10104 sql = _SQL_SELECT_ASSETCATEGORY;
10105
10106 if (pagination) {
10107 sql = sql.concat(AssetCategoryModelImpl.ORDER_BY_JPQL);
10108 }
10109 }
10110
10111 Session session = null;
10112
10113 try {
10114 session = openSession();
10115
10116 Query q = session.createQuery(sql);
10117
10118 if (!pagination) {
10119 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
10120 start, end, false);
10121
10122 Collections.sort(list);
10123
10124 list = new UnmodifiableList<AssetCategory>(list);
10125 }
10126 else {
10127 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
10128 start, end);
10129 }
10130
10131 cacheResult(list);
10132
10133 FinderCacheUtil.putResult(finderPath, finderArgs, list);
10134 }
10135 catch (Exception e) {
10136 FinderCacheUtil.removeResult(finderPath, finderArgs);
10137
10138 throw processException(e);
10139 }
10140 finally {
10141 closeSession(session);
10142 }
10143 }
10144
10145 return list;
10146 }
10147
10148
10153 public void removeAll() throws SystemException {
10154 for (AssetCategory assetCategory : findAll()) {
10155 remove(assetCategory);
10156 }
10157 }
10158
10159
10165 public int countAll() throws SystemException {
10166 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
10167 FINDER_ARGS_EMPTY, this);
10168
10169 if (count == null) {
10170 Session session = null;
10171
10172 try {
10173 session = openSession();
10174
10175 Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORY);
10176
10177 count = (Long)q.uniqueResult();
10178
10179 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
10180 FINDER_ARGS_EMPTY, count);
10181 }
10182 catch (Exception e) {
10183 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
10184 FINDER_ARGS_EMPTY);
10185
10186 throw processException(e);
10187 }
10188 finally {
10189 closeSession(session);
10190 }
10191 }
10192
10193 return count.intValue();
10194 }
10195
10196
10203 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
10204 long pk) throws SystemException {
10205 return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
10206 }
10207
10208
10221 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
10222 long pk, int start, int end) throws SystemException {
10223 return getAssetEntries(pk, start, end, null);
10224 }
10225
10226 public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
10227 AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
10228 com.liferay.portlet.asset.model.impl.AssetEntryImpl.class,
10229 AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
10230 "getAssetEntries",
10231 new String[] {
10232 Long.class.getName(), Integer.class.getName(),
10233 Integer.class.getName(), OrderByComparator.class.getName()
10234 });
10235
10236 static {
10237 FINDER_PATH_GET_ASSETENTRIES.setCacheKeyGeneratorCacheName(null);
10238 }
10239
10240
10254 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
10255 long pk, int start, int end, OrderByComparator orderByComparator)
10256 throws SystemException {
10257 boolean pagination = true;
10258 Object[] finderArgs = null;
10259
10260 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10261 (orderByComparator == null)) {
10262 pagination = false;
10263 finderArgs = new Object[] { pk };
10264 }
10265 else {
10266 finderArgs = new Object[] { pk, start, end, orderByComparator };
10267 }
10268
10269 List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
10270 finderArgs, this);
10271
10272 if (list == null) {
10273 Session session = null;
10274
10275 try {
10276 session = openSession();
10277
10278 String sql = null;
10279
10280 if (orderByComparator != null) {
10281 sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
10282 .concat(orderByComparator.getOrderBy());
10283 }
10284 else {
10285 sql = _SQL_GETASSETENTRIES;
10286
10287 if (pagination) {
10288 sql = sql.concat(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ORDER_BY_SQL);
10289 }
10290 }
10291
10292 SQLQuery q = session.createSQLQuery(sql);
10293
10294 q.addEntity("AssetEntry",
10295 com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
10296
10297 QueryPos qPos = QueryPos.getInstance(q);
10298
10299 qPos.add(pk);
10300
10301 if (!pagination) {
10302 list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
10303 getDialect(), start, end, false);
10304
10305 Collections.sort(list);
10306
10307 list = new UnmodifiableList<com.liferay.portlet.asset.model.AssetEntry>(list);
10308 }
10309 else {
10310 list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
10311 getDialect(), start, end);
10312 }
10313
10314 assetEntryPersistence.cacheResult(list);
10315
10316 FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
10317 finderArgs, list);
10318 }
10319 catch (Exception e) {
10320 FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES,
10321 finderArgs);
10322
10323 throw processException(e);
10324 }
10325 finally {
10326 closeSession(session);
10327 }
10328 }
10329
10330 return list;
10331 }
10332
10333 public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
10334 AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
10335 Long.class,
10336 AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
10337 "getAssetEntriesSize", new String[] { Long.class.getName() });
10338
10339 static {
10340 FINDER_PATH_GET_ASSETENTRIES_SIZE.setCacheKeyGeneratorCacheName(null);
10341 }
10342
10343
10350 public int getAssetEntriesSize(long pk) throws SystemException {
10351 Object[] finderArgs = new Object[] { pk };
10352
10353 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
10354 finderArgs, this);
10355
10356 if (count == null) {
10357 Session session = null;
10358
10359 try {
10360 session = openSession();
10361
10362 SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
10363
10364 q.addScalar(COUNT_COLUMN_NAME,
10365 com.liferay.portal.kernel.dao.orm.Type.LONG);
10366
10367 QueryPos qPos = QueryPos.getInstance(q);
10368
10369 qPos.add(pk);
10370
10371 count = (Long)q.uniqueResult();
10372
10373 FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
10374 finderArgs, count);
10375 }
10376 catch (Exception e) {
10377 FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
10378 finderArgs);
10379
10380 throw processException(e);
10381 }
10382 finally {
10383 closeSession(session);
10384 }
10385 }
10386
10387 return count.intValue();
10388 }
10389
10390 public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
10391 AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
10392 Boolean.class,
10393 AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
10394 "containsAssetEntry",
10395 new String[] { Long.class.getName(), Long.class.getName() });
10396
10397
10405 public boolean containsAssetEntry(long pk, long assetEntryPK)
10406 throws SystemException {
10407 Object[] finderArgs = new Object[] { pk, assetEntryPK };
10408
10409 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
10410 finderArgs, this);
10411
10412 if (value == null) {
10413 try {
10414 value = Boolean.valueOf(containsAssetEntry.contains(pk,
10415 assetEntryPK));
10416
10417 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
10418 finderArgs, value);
10419 }
10420 catch (Exception e) {
10421 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_ASSETENTRY,
10422 finderArgs);
10423
10424 throw processException(e);
10425 }
10426 }
10427
10428 return value.booleanValue();
10429 }
10430
10431
10438 public boolean containsAssetEntries(long pk) throws SystemException {
10439 if (getAssetEntriesSize(pk) > 0) {
10440 return true;
10441 }
10442 else {
10443 return false;
10444 }
10445 }
10446
10447
10454 public void addAssetEntry(long pk, long assetEntryPK)
10455 throws SystemException {
10456 try {
10457 addAssetEntry.add(pk, assetEntryPK);
10458 }
10459 catch (Exception e) {
10460 throw processException(e);
10461 }
10462 finally {
10463 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10464 }
10465 }
10466
10467
10474 public void addAssetEntry(long pk,
10475 com.liferay.portlet.asset.model.AssetEntry assetEntry)
10476 throws SystemException {
10477 try {
10478 addAssetEntry.add(pk, assetEntry.getPrimaryKey());
10479 }
10480 catch (Exception e) {
10481 throw processException(e);
10482 }
10483 finally {
10484 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10485 }
10486 }
10487
10488
10495 public void addAssetEntries(long pk, long[] assetEntryPKs)
10496 throws SystemException {
10497 try {
10498 for (long assetEntryPK : assetEntryPKs) {
10499 addAssetEntry.add(pk, assetEntryPK);
10500 }
10501 }
10502 catch (Exception e) {
10503 throw processException(e);
10504 }
10505 finally {
10506 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10507 }
10508 }
10509
10510
10517 public void addAssetEntries(long pk,
10518 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
10519 throws SystemException {
10520 try {
10521 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
10522 addAssetEntry.add(pk, assetEntry.getPrimaryKey());
10523 }
10524 }
10525 catch (Exception e) {
10526 throw processException(e);
10527 }
10528 finally {
10529 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10530 }
10531 }
10532
10533
10539 public void clearAssetEntries(long pk) throws SystemException {
10540 try {
10541 clearAssetEntries.clear(pk);
10542 }
10543 catch (Exception e) {
10544 throw processException(e);
10545 }
10546 finally {
10547 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10548 }
10549 }
10550
10551
10558 public void removeAssetEntry(long pk, long assetEntryPK)
10559 throws SystemException {
10560 try {
10561 removeAssetEntry.remove(pk, assetEntryPK);
10562 }
10563 catch (Exception e) {
10564 throw processException(e);
10565 }
10566 finally {
10567 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10568 }
10569 }
10570
10571
10578 public void removeAssetEntry(long pk,
10579 com.liferay.portlet.asset.model.AssetEntry assetEntry)
10580 throws SystemException {
10581 try {
10582 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
10583 }
10584 catch (Exception e) {
10585 throw processException(e);
10586 }
10587 finally {
10588 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10589 }
10590 }
10591
10592
10599 public void removeAssetEntries(long pk, long[] assetEntryPKs)
10600 throws SystemException {
10601 try {
10602 for (long assetEntryPK : assetEntryPKs) {
10603 removeAssetEntry.remove(pk, assetEntryPK);
10604 }
10605 }
10606 catch (Exception e) {
10607 throw processException(e);
10608 }
10609 finally {
10610 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10611 }
10612 }
10613
10614
10621 public void removeAssetEntries(long pk,
10622 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
10623 throws SystemException {
10624 try {
10625 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
10626 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
10627 }
10628 }
10629 catch (Exception e) {
10630 throw processException(e);
10631 }
10632 finally {
10633 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10634 }
10635 }
10636
10637
10644 public void setAssetEntries(long pk, long[] assetEntryPKs)
10645 throws SystemException {
10646 try {
10647 Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
10648
10649 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
10650
10651 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
10652 if (!assetEntryPKSet.remove(assetEntry.getPrimaryKey())) {
10653 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
10654 }
10655 }
10656
10657 for (Long assetEntryPK : assetEntryPKSet) {
10658 addAssetEntry.add(pk, assetEntryPK);
10659 }
10660 }
10661 catch (Exception e) {
10662 throw processException(e);
10663 }
10664 finally {
10665 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10666 }
10667 }
10668
10669
10676 public void setAssetEntries(long pk,
10677 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
10678 throws SystemException {
10679 try {
10680 long[] assetEntryPKs = new long[assetEntries.size()];
10681
10682 for (int i = 0; i < assetEntries.size(); i++) {
10683 com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
10684
10685 assetEntryPKs[i] = assetEntry.getPrimaryKey();
10686 }
10687
10688 setAssetEntries(pk, assetEntryPKs);
10689 }
10690 catch (Exception e) {
10691 throw processException(e);
10692 }
10693 finally {
10694 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
10695 }
10696 }
10697
10698
10708 public void rebuildTree(long groupId, boolean force)
10709 throws SystemException {
10710 if (!rebuildTreeEnabled) {
10711 return;
10712 }
10713
10714 if (force || (countOrphanTreeNodes(groupId) > 0)) {
10715 rebuildTree(groupId, 0, 1);
10716
10717 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
10718 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
10719 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
10720 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10721 }
10722 }
10723
10724 public void setRebuildTreeEnabled(boolean rebuildTreeEnabled) {
10725 this.rebuildTreeEnabled = rebuildTreeEnabled;
10726 }
10727
10728 protected long countOrphanTreeNodes(long groupId) throws SystemException {
10729 Session session = null;
10730
10731 try {
10732 session = openSession();
10733
10734 SQLQuery q = session.createSQLQuery(
10735 "SELECT COUNT(*) AS COUNT_VALUE FROM AssetCategory WHERE groupId = ? AND (leftCategoryId = 0 OR leftCategoryId IS NULL OR rightCategoryId = 0 OR rightCategoryId IS NULL)");
10736
10737 q.addScalar(COUNT_COLUMN_NAME,
10738 com.liferay.portal.kernel.dao.orm.Type.LONG);
10739
10740 QueryPos qPos = QueryPos.getInstance(q);
10741
10742 qPos.add(groupId);
10743
10744 return (Long)q.uniqueResult();
10745 }
10746 catch (Exception e) {
10747 throw processException(e);
10748 }
10749 finally {
10750 closeSession(session);
10751 }
10752 }
10753
10754 protected void expandNoChildrenLeftCategoryId(long groupId,
10755 long leftCategoryId, List<Long> childrenCategoryIds, long delta) {
10756 String sql = "UPDATE AssetCategory SET leftcategoryId = (leftcategoryId + ?) WHERE (groupId = ?) AND (leftcategoryId > ?) AND (categoryId NOT IN (" +
10757 StringUtil.merge(childrenCategoryIds) + "))";
10758
10759 SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
10760 sql,
10761 new int[] {
10762 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
10763 java.sql.Types.BIGINT
10764 });
10765
10766 _sqlUpdate.update(new Object[] { delta, groupId, leftCategoryId });
10767 }
10768
10769 protected void expandNoChildrenRightCategoryId(long groupId,
10770 long rightCategoryId, List<Long> childrenCategoryIds, long delta) {
10771 String sql = "UPDATE AssetCategory SET rightcategoryId = (rightcategoryId + ?) WHERE (groupId = ?) AND (rightcategoryId > ?) AND (categoryId NOT IN (" +
10772 StringUtil.merge(childrenCategoryIds) + "))";
10773
10774 SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
10775 sql,
10776 new int[] {
10777 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
10778 java.sql.Types.BIGINT
10779 });
10780
10781 _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
10782 }
10783
10784 protected void expandTree(AssetCategory assetCategory,
10785 List<Long> childrenCategoryIds) throws SystemException {
10786 if (!rebuildTreeEnabled) {
10787 return;
10788 }
10789
10790 long groupId = assetCategory.getGroupId();
10791
10792 long lastRightCategoryId = getLastRightCategoryId(groupId,
10793 assetCategory.getParentCategoryId());
10794
10795 long leftCategoryId = 2;
10796 long rightCategoryId = 3;
10797
10798 if (lastRightCategoryId > 0) {
10799 leftCategoryId = lastRightCategoryId + 1;
10800
10801 long childrenDistance = assetCategory.getRightCategoryId() -
10802 assetCategory.getLeftCategoryId();
10803
10804 if (childrenDistance > 1) {
10805 rightCategoryId = leftCategoryId + childrenDistance;
10806
10807 updateChildrenTree(groupId, childrenCategoryIds,
10808 leftCategoryId - assetCategory.getLeftCategoryId());
10809
10810 expandNoChildrenLeftCategoryId(groupId, lastRightCategoryId,
10811 childrenCategoryIds, childrenDistance + 1);
10812 expandNoChildrenRightCategoryId(groupId, lastRightCategoryId,
10813 childrenCategoryIds, childrenDistance + 1);
10814 }
10815 else {
10816 rightCategoryId = lastRightCategoryId + 2;
10817
10818 expandTreeLeftCategoryId.expand(groupId, lastRightCategoryId);
10819 expandTreeRightCategoryId.expand(groupId, lastRightCategoryId);
10820 }
10821
10822 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
10823 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
10824 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
10825 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10826 }
10827
10828 assetCategory.setLeftCategoryId(leftCategoryId);
10829 assetCategory.setRightCategoryId(rightCategoryId);
10830 }
10831
10832 protected List<Long> getChildrenTreeCategoryIds(
10833 AssetCategory parentAssetCategory) throws SystemException {
10834 Session session = null;
10835
10836 try {
10837 session = openSession();
10838
10839 SQLQuery q = session.createSQLQuery(
10840 "SELECT categoryId FROM AssetCategory WHERE (groupId = ?) AND (leftcategoryId BETWEEN ? AND ?)");
10841
10842 q.addScalar("CategoryId",
10843 com.liferay.portal.kernel.dao.orm.Type.LONG);
10844
10845 QueryPos qPos = QueryPos.getInstance(q);
10846
10847 qPos.add(parentAssetCategory.getGroupId());
10848 qPos.add(parentAssetCategory.getLeftCategoryId() + 1);
10849 qPos.add(parentAssetCategory.getRightCategoryId());
10850
10851 return q.list();
10852 }
10853 catch (Exception e) {
10854 throw processException(e);
10855 }
10856 finally {
10857 closeSession(session);
10858 }
10859 }
10860
10861 protected long getLastRightCategoryId(long groupId, long parentCategoryId)
10862 throws SystemException {
10863 Session session = null;
10864
10865 try {
10866 session = openSession();
10867
10868 SQLQuery q = session.createSQLQuery(
10869 "SELECT rightCategoryId FROM AssetCategory WHERE (groupId = ?) AND (parentCategoryId = ?) ORDER BY rightCategoryId DESC");
10870
10871 q.addScalar("rightCategoryId",
10872 com.liferay.portal.kernel.dao.orm.Type.LONG);
10873
10874 QueryPos qPos = QueryPos.getInstance(q);
10875
10876 qPos.add(groupId);
10877 qPos.add(parentCategoryId);
10878
10879 List<Long> list = (List<Long>)QueryUtil.list(q, getDialect(), 0, 1);
10880
10881 if (list.isEmpty()) {
10882 if (parentCategoryId > 0) {
10883 session.clear();
10884
10885 AssetCategory parentAssetCategory = findByPrimaryKey(parentCategoryId);
10886
10887 return parentAssetCategory.getLeftCategoryId();
10888 }
10889
10890 return 0;
10891 }
10892 else {
10893 return list.get(0);
10894 }
10895 }
10896 catch (Exception e) {
10897 throw processException(e);
10898 }
10899 finally {
10900 closeSession(session);
10901 }
10902 }
10903
10904 protected long rebuildTree(long groupId, long parentCategoryId,
10905 long leftCategoryId) throws SystemException {
10906 if (!rebuildTreeEnabled) {
10907 return 0;
10908 }
10909
10910 List<Long> categoryIds = null;
10911
10912 Session session = null;
10913
10914 try {
10915 session = openSession();
10916
10917 SQLQuery q = session.createSQLQuery(
10918 "SELECT categoryId FROM AssetCategory WHERE groupId = ? AND parentCategoryId = ? ORDER BY categoryId ASC");
10919
10920 q.addScalar("categoryId",
10921 com.liferay.portal.kernel.dao.orm.Type.LONG);
10922
10923 QueryPos qPos = QueryPos.getInstance(q);
10924
10925 qPos.add(groupId);
10926 qPos.add(parentCategoryId);
10927
10928 categoryIds = q.list();
10929 }
10930 catch (Exception e) {
10931 throw processException(e);
10932 }
10933 finally {
10934 closeSession(session);
10935 }
10936
10937 long rightCategoryId = leftCategoryId + 1;
10938
10939 for (long categoryId : categoryIds) {
10940 rightCategoryId = rebuildTree(groupId, categoryId, rightCategoryId);
10941 }
10942
10943 if (parentCategoryId > 0) {
10944 updateTree.update(parentCategoryId, leftCategoryId, rightCategoryId);
10945 }
10946
10947 return rightCategoryId + 1;
10948 }
10949
10950 protected void shrinkTree(AssetCategory assetCategory) {
10951 if (!rebuildTreeEnabled) {
10952 return;
10953 }
10954
10955 long groupId = assetCategory.getGroupId();
10956
10957 long leftCategoryId = assetCategory.getLeftCategoryId();
10958 long rightCategoryId = assetCategory.getRightCategoryId();
10959
10960 long delta = (rightCategoryId - leftCategoryId) + 1;
10961
10962 shrinkTreeLeftCategoryId.shrink(groupId, rightCategoryId, delta);
10963 shrinkTreeRightCategoryId.shrink(groupId, rightCategoryId, delta);
10964
10965 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
10966 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
10967 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
10968 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10969 }
10970
10971 protected void updateChildrenTree(long groupId,
10972 List<Long> childrenCategoryIds, long delta) {
10973 String sql = "UPDATE AssetCategory SET leftcategoryId = (leftcategoryId + ?), rightcategoryId = (rightcategoryId + ?) WHERE (groupId = ?) AND (categoryId IN (" +
10974 StringUtil.merge(childrenCategoryIds) + "))";
10975
10976 SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
10977 sql,
10978 new int[] {
10979 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
10980 java.sql.Types.BIGINT
10981 });
10982
10983 _sqlUpdate.update(new Object[] { delta, delta, groupId });
10984 }
10985
10986
10989 public void afterPropertiesSet() {
10990 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
10991 com.liferay.portal.util.PropsUtil.get(
10992 "value.object.listener.com.liferay.portlet.asset.model.AssetCategory")));
10993
10994 if (listenerClassNames.length > 0) {
10995 try {
10996 List<ModelListener<AssetCategory>> listenersList = new ArrayList<ModelListener<AssetCategory>>();
10997
10998 for (String listenerClassName : listenerClassNames) {
10999 listenersList.add((ModelListener<AssetCategory>)InstanceFactory.newInstance(
11000 listenerClassName));
11001 }
11002
11003 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
11004 }
11005 catch (Exception e) {
11006 _log.error(e);
11007 }
11008 }
11009
11010 containsAssetEntry = new ContainsAssetEntry();
11011
11012 addAssetEntry = new AddAssetEntry();
11013 clearAssetEntries = new ClearAssetEntries();
11014 removeAssetEntry = new RemoveAssetEntry();
11015
11016 expandTreeLeftCategoryId = new ExpandTreeLeftCategoryId();
11017 expandTreeRightCategoryId = new ExpandTreeRightCategoryId();
11018 shrinkTreeLeftCategoryId = new ShrinkTreeLeftCategoryId();
11019 shrinkTreeRightCategoryId = new ShrinkTreeRightCategoryId();
11020 updateTree = new UpdateTree();
11021 }
11022
11023 public void destroy() {
11024 EntityCacheUtil.removeCache(AssetCategoryImpl.class.getName());
11025 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
11026 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11027 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11028 }
11029
11030 @BeanReference(type = AssetEntryPersistence.class)
11031 protected AssetEntryPersistence assetEntryPersistence;
11032 protected ContainsAssetEntry containsAssetEntry;
11033 protected AddAssetEntry addAssetEntry;
11034 protected ClearAssetEntries clearAssetEntries;
11035 protected RemoveAssetEntry removeAssetEntry;
11036
11037 protected class ContainsAssetEntry {
11038 protected ContainsAssetEntry() {
11039 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
11040 _SQL_CONTAINSASSETENTRY,
11041 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
11042 RowMapper.COUNT);
11043 }
11044
11045 protected boolean contains(long categoryId, long entryId) {
11046 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
11047 new Long(categoryId), new Long(entryId)
11048 });
11049
11050 if (results.size() > 0) {
11051 Integer count = results.get(0);
11052
11053 if (count.intValue() > 0) {
11054 return true;
11055 }
11056 }
11057
11058 return false;
11059 }
11060
11061 private MappingSqlQuery<Integer> _mappingSqlQuery;
11062 }
11063
11064 protected class AddAssetEntry {
11065 protected AddAssetEntry() {
11066 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11067 "INSERT INTO AssetEntries_AssetCategories (categoryId, entryId) VALUES (?, ?)",
11068 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
11069 }
11070
11071 protected void add(long categoryId, long entryId)
11072 throws SystemException {
11073 if (!containsAssetEntry.contains(categoryId, entryId)) {
11074 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
11075 assetEntryPersistence.getListeners();
11076
11077 for (ModelListener<AssetCategory> listener : listeners) {
11078 listener.onBeforeAddAssociation(categoryId,
11079 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
11080 entryId);
11081 }
11082
11083 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
11084 listener.onBeforeAddAssociation(entryId,
11085 AssetCategory.class.getName(), categoryId);
11086 }
11087
11088 _sqlUpdate.update(new Object[] {
11089 new Long(categoryId), new Long(entryId)
11090 });
11091
11092 for (ModelListener<AssetCategory> listener : listeners) {
11093 listener.onAfterAddAssociation(categoryId,
11094 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
11095 entryId);
11096 }
11097
11098 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
11099 listener.onAfterAddAssociation(entryId,
11100 AssetCategory.class.getName(), categoryId);
11101 }
11102 }
11103 }
11104
11105 private SqlUpdate _sqlUpdate;
11106 }
11107
11108 protected class ClearAssetEntries {
11109 protected ClearAssetEntries() {
11110 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11111 "DELETE FROM AssetEntries_AssetCategories WHERE categoryId = ?",
11112 new int[] { java.sql.Types.BIGINT });
11113 }
11114
11115 protected void clear(long categoryId) throws SystemException {
11116 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
11117 assetEntryPersistence.getListeners();
11118
11119 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
11120
11121 if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
11122 assetEntries = getAssetEntries(categoryId);
11123
11124 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
11125 for (ModelListener<AssetCategory> listener : listeners) {
11126 listener.onBeforeRemoveAssociation(categoryId,
11127 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
11128 assetEntry.getPrimaryKey());
11129 }
11130
11131 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
11132 listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
11133 AssetCategory.class.getName(), categoryId);
11134 }
11135 }
11136 }
11137
11138 _sqlUpdate.update(new Object[] { new Long(categoryId) });
11139
11140 if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
11141 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
11142 for (ModelListener<AssetCategory> listener : listeners) {
11143 listener.onAfterRemoveAssociation(categoryId,
11144 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
11145 assetEntry.getPrimaryKey());
11146 }
11147
11148 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
11149 listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
11150 AssetCategory.class.getName(), categoryId);
11151 }
11152 }
11153 }
11154 }
11155
11156 private SqlUpdate _sqlUpdate;
11157 }
11158
11159 protected class RemoveAssetEntry {
11160 protected RemoveAssetEntry() {
11161 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11162 "DELETE FROM AssetEntries_AssetCategories WHERE categoryId = ? AND entryId = ?",
11163 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
11164 }
11165
11166 protected void remove(long categoryId, long entryId)
11167 throws SystemException {
11168 if (containsAssetEntry.contains(categoryId, entryId)) {
11169 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
11170 assetEntryPersistence.getListeners();
11171
11172 for (ModelListener<AssetCategory> listener : listeners) {
11173 listener.onBeforeRemoveAssociation(categoryId,
11174 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
11175 entryId);
11176 }
11177
11178 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
11179 listener.onBeforeRemoveAssociation(entryId,
11180 AssetCategory.class.getName(), categoryId);
11181 }
11182
11183 _sqlUpdate.update(new Object[] {
11184 new Long(categoryId), new Long(entryId)
11185 });
11186
11187 for (ModelListener<AssetCategory> listener : listeners) {
11188 listener.onAfterRemoveAssociation(categoryId,
11189 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
11190 entryId);
11191 }
11192
11193 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
11194 listener.onAfterRemoveAssociation(entryId,
11195 AssetCategory.class.getName(), categoryId);
11196 }
11197 }
11198 }
11199
11200 private SqlUpdate _sqlUpdate;
11201 }
11202
11203 protected boolean rebuildTreeEnabled = true;
11204 protected ExpandTreeLeftCategoryId expandTreeLeftCategoryId;
11205 protected ExpandTreeRightCategoryId expandTreeRightCategoryId;
11206 protected ShrinkTreeLeftCategoryId shrinkTreeLeftCategoryId;
11207 protected ShrinkTreeRightCategoryId shrinkTreeRightCategoryId;
11208 protected UpdateTree updateTree;
11209
11210 protected class ExpandTreeLeftCategoryId {
11211 protected ExpandTreeLeftCategoryId() {
11212 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11213 "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId + 2) WHERE (groupId = ?) AND (leftCategoryId > ?)",
11214 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
11215 }
11216
11217 protected void expand(long groupId, long leftCategoryId) {
11218 _sqlUpdate.update(new Object[] { groupId, leftCategoryId });
11219 }
11220
11221 private SqlUpdate _sqlUpdate;
11222 }
11223
11224 protected class ExpandTreeRightCategoryId {
11225 protected ExpandTreeRightCategoryId() {
11226 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11227 "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId + 2) WHERE (groupId = ?) AND (rightCategoryId > ?)",
11228 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
11229 }
11230
11231 protected void expand(long groupId, long rightCategoryId) {
11232 _sqlUpdate.update(new Object[] { groupId, rightCategoryId });
11233 }
11234
11235 private SqlUpdate _sqlUpdate;
11236 }
11237
11238 protected class ShrinkTreeLeftCategoryId {
11239 protected ShrinkTreeLeftCategoryId() {
11240 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11241 "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId - ?) WHERE (groupId = ?) AND (leftCategoryId > ?)",
11242 new int[] {
11243 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
11244 java.sql.Types.BIGINT
11245 });
11246 }
11247
11248 protected void shrink(long groupId, long rightCategoryId, long delta) {
11249 _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
11250 }
11251
11252 private SqlUpdate _sqlUpdate;
11253 }
11254
11255 protected class ShrinkTreeRightCategoryId {
11256 protected ShrinkTreeRightCategoryId() {
11257 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11258 "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId - ?) WHERE (groupId = ?) AND (rightCategoryId > ?)",
11259 new int[] {
11260 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
11261 java.sql.Types.BIGINT
11262 });
11263 }
11264
11265 protected void shrink(long groupId, long rightCategoryId, long delta) {
11266 _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
11267 }
11268
11269 private SqlUpdate _sqlUpdate;
11270 }
11271
11272 protected class UpdateTree {
11273 protected UpdateTree() {
11274 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11275 "UPDATE AssetCategory SET leftCategoryId = ?, rightCategoryId = ? WHERE categoryId = ?",
11276 new int[] {
11277 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
11278 java.sql.Types.BIGINT
11279 });
11280 }
11281
11282 protected void update(long categoryId, long leftCategoryId,
11283 long rightCategoryId) {
11284 _sqlUpdate.update(new Object[] {
11285 leftCategoryId, rightCategoryId, categoryId
11286 });
11287 }
11288
11289 private SqlUpdate _sqlUpdate;
11290 }
11291
11292 private static final String _SQL_SELECT_ASSETCATEGORY = "SELECT assetCategory FROM AssetCategory assetCategory";
11293 private static final String _SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT assetCategory FROM AssetCategory assetCategory WHERE ";
11294 private static final String _SQL_COUNT_ASSETCATEGORY = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory";
11295 private static final String _SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory WHERE ";
11296 private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetCategories ON (AssetEntries_AssetCategories.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetCategories.categoryId = ?)";
11297 private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE categoryId = ?";
11298 private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE categoryId = ? AND entryId = ?";
11299 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetCategory.categoryId";
11300 private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT DISTINCT {assetCategory.*} FROM AssetCategory assetCategory WHERE ";
11301 private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
11302 "SELECT {AssetCategory.*} FROM (SELECT DISTINCT assetCategory.categoryId FROM AssetCategory assetCategory WHERE ";
11303 private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
11304 ") TEMP_TABLE INNER JOIN AssetCategory ON TEMP_TABLE.categoryId = AssetCategory.categoryId";
11305 private static final String _FILTER_SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(DISTINCT assetCategory.categoryId) AS COUNT_VALUE FROM AssetCategory assetCategory WHERE ";
11306 private static final String _FILTER_ENTITY_ALIAS = "assetCategory";
11307 private static final String _FILTER_ENTITY_TABLE = "AssetCategory";
11308 private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategory.";
11309 private static final String _ORDER_BY_ENTITY_TABLE = "AssetCategory.";
11310 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategory exists with the primary key ";
11311 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategory exists with the key {";
11312 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
11313 private static Log _log = LogFactoryUtil.getLog(AssetCategoryPersistenceImpl.class);
11314 private static AssetCategory _nullAssetCategory = new AssetCategoryImpl() {
11315 @Override
11316 public Object clone() {
11317 return this;
11318 }
11319
11320 @Override
11321 public CacheModel<AssetCategory> toCacheModel() {
11322 return _nullAssetCategoryCacheModel;
11323 }
11324 };
11325
11326 private static CacheModel<AssetCategory> _nullAssetCategoryCacheModel = new CacheModel<AssetCategory>() {
11327 public AssetCategory toEntityModel() {
11328 return _nullAssetCategory;
11329 }
11330 };
11331 }