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.SqlUpdate;
020 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.SQLQuery;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.exception.SystemException;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.util.ArrayUtil;
033 import com.liferay.portal.kernel.util.CharPool;
034 import com.liferay.portal.kernel.util.GetterUtil;
035 import com.liferay.portal.kernel.util.InstanceFactory;
036 import com.liferay.portal.kernel.util.OrderByComparator;
037 import com.liferay.portal.kernel.util.SetUtil;
038 import com.liferay.portal.kernel.util.StringBundler;
039 import com.liferay.portal.kernel.util.StringPool;
040 import com.liferay.portal.kernel.util.StringUtil;
041 import com.liferay.portal.kernel.util.UnmodifiableList;
042 import com.liferay.portal.kernel.util.Validator;
043 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044 import com.liferay.portal.model.CacheModel;
045 import com.liferay.portal.model.ModelListener;
046 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048 import com.liferay.portal.service.persistence.impl.TableMapper;
049 import com.liferay.portal.service.persistence.impl.TableMapperFactory;
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.HashSet;
061 import java.util.List;
062 import java.util.Set;
063
064
076 public class AssetCategoryPersistenceImpl extends BasePersistenceImpl<AssetCategory>
077 implements AssetCategoryPersistence {
078
083 public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryImpl.class.getName();
084 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085 ".List1";
086 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087 ".List2";
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
089 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
090 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findAll", new String[0]);
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
093 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
094 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
095 "findAll", new String[0]);
096 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
097 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
099 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
100 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
101 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
102 "findByUuid",
103 new String[] {
104 String.class.getName(),
105
106 Integer.class.getName(), Integer.class.getName(),
107 OrderByComparator.class.getName()
108 });
109 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
110 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
111 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
112 "findByUuid", new String[] { String.class.getName() },
113 AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
114 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
115 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
116 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
117 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
118 new String[] { String.class.getName() });
119
120
127 @Override
128 public List<AssetCategory> findByUuid(String uuid)
129 throws SystemException {
130 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
131 }
132
133
146 @Override
147 public List<AssetCategory> findByUuid(String uuid, int start, int end)
148 throws SystemException {
149 return findByUuid(uuid, start, end, null);
150 }
151
152
166 @Override
167 public List<AssetCategory> findByUuid(String uuid, int start, int end,
168 OrderByComparator orderByComparator) throws SystemException {
169 boolean pagination = true;
170 FinderPath finderPath = null;
171 Object[] finderArgs = null;
172
173 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
174 (orderByComparator == null)) {
175 pagination = false;
176 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
177 finderArgs = new Object[] { uuid };
178 }
179 else {
180 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
181 finderArgs = new Object[] { uuid, start, end, orderByComparator };
182 }
183
184 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
185 finderArgs, this);
186
187 if ((list != null) && !list.isEmpty()) {
188 for (AssetCategory assetCategory : list) {
189 if (!Validator.equals(uuid, assetCategory.getUuid())) {
190 list = null;
191
192 break;
193 }
194 }
195 }
196
197 if (list == null) {
198 StringBundler query = null;
199
200 if (orderByComparator != null) {
201 query = new StringBundler(3 +
202 (orderByComparator.getOrderByFields().length * 3));
203 }
204 else {
205 query = new StringBundler(3);
206 }
207
208 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
209
210 boolean bindUuid = false;
211
212 if (uuid == null) {
213 query.append(_FINDER_COLUMN_UUID_UUID_1);
214 }
215 else if (uuid.equals(StringPool.BLANK)) {
216 query.append(_FINDER_COLUMN_UUID_UUID_3);
217 }
218 else {
219 bindUuid = true;
220
221 query.append(_FINDER_COLUMN_UUID_UUID_2);
222 }
223
224 if (orderByComparator != null) {
225 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
226 orderByComparator);
227 }
228 else
229 if (pagination) {
230 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
231 }
232
233 String sql = query.toString();
234
235 Session session = null;
236
237 try {
238 session = openSession();
239
240 Query q = session.createQuery(sql);
241
242 QueryPos qPos = QueryPos.getInstance(q);
243
244 if (bindUuid) {
245 qPos.add(uuid);
246 }
247
248 if (!pagination) {
249 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
250 start, end, false);
251
252 Collections.sort(list);
253
254 list = new UnmodifiableList<AssetCategory>(list);
255 }
256 else {
257 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
258 start, end);
259 }
260
261 cacheResult(list);
262
263 FinderCacheUtil.putResult(finderPath, finderArgs, list);
264 }
265 catch (Exception e) {
266 FinderCacheUtil.removeResult(finderPath, finderArgs);
267
268 throw processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273 }
274
275 return list;
276 }
277
278
287 @Override
288 public AssetCategory findByUuid_First(String uuid,
289 OrderByComparator orderByComparator)
290 throws NoSuchCategoryException, SystemException {
291 AssetCategory assetCategory = fetchByUuid_First(uuid, orderByComparator);
292
293 if (assetCategory != null) {
294 return assetCategory;
295 }
296
297 StringBundler msg = new StringBundler(4);
298
299 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
300
301 msg.append("uuid=");
302 msg.append(uuid);
303
304 msg.append(StringPool.CLOSE_CURLY_BRACE);
305
306 throw new NoSuchCategoryException(msg.toString());
307 }
308
309
317 @Override
318 public AssetCategory fetchByUuid_First(String uuid,
319 OrderByComparator orderByComparator) throws SystemException {
320 List<AssetCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
321
322 if (!list.isEmpty()) {
323 return list.get(0);
324 }
325
326 return null;
327 }
328
329
338 @Override
339 public AssetCategory findByUuid_Last(String uuid,
340 OrderByComparator orderByComparator)
341 throws NoSuchCategoryException, SystemException {
342 AssetCategory assetCategory = fetchByUuid_Last(uuid, orderByComparator);
343
344 if (assetCategory != null) {
345 return assetCategory;
346 }
347
348 StringBundler msg = new StringBundler(4);
349
350 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
351
352 msg.append("uuid=");
353 msg.append(uuid);
354
355 msg.append(StringPool.CLOSE_CURLY_BRACE);
356
357 throw new NoSuchCategoryException(msg.toString());
358 }
359
360
368 @Override
369 public AssetCategory fetchByUuid_Last(String uuid,
370 OrderByComparator orderByComparator) throws SystemException {
371 int count = countByUuid(uuid);
372
373 if (count == 0) {
374 return null;
375 }
376
377 List<AssetCategory> list = findByUuid(uuid, count - 1, count,
378 orderByComparator);
379
380 if (!list.isEmpty()) {
381 return list.get(0);
382 }
383
384 return null;
385 }
386
387
397 @Override
398 public AssetCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
399 OrderByComparator orderByComparator)
400 throws NoSuchCategoryException, SystemException {
401 AssetCategory assetCategory = findByPrimaryKey(categoryId);
402
403 Session session = null;
404
405 try {
406 session = openSession();
407
408 AssetCategory[] array = new AssetCategoryImpl[3];
409
410 array[0] = getByUuid_PrevAndNext(session, assetCategory, uuid,
411 orderByComparator, true);
412
413 array[1] = assetCategory;
414
415 array[2] = getByUuid_PrevAndNext(session, assetCategory, uuid,
416 orderByComparator, false);
417
418 return array;
419 }
420 catch (Exception e) {
421 throw processException(e);
422 }
423 finally {
424 closeSession(session);
425 }
426 }
427
428 protected AssetCategory getByUuid_PrevAndNext(Session session,
429 AssetCategory assetCategory, String uuid,
430 OrderByComparator orderByComparator, boolean previous) {
431 StringBundler query = null;
432
433 if (orderByComparator != null) {
434 query = new StringBundler(6 +
435 (orderByComparator.getOrderByFields().length * 6));
436 }
437 else {
438 query = new StringBundler(3);
439 }
440
441 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
442
443 boolean bindUuid = false;
444
445 if (uuid == null) {
446 query.append(_FINDER_COLUMN_UUID_UUID_1);
447 }
448 else if (uuid.equals(StringPool.BLANK)) {
449 query.append(_FINDER_COLUMN_UUID_UUID_3);
450 }
451 else {
452 bindUuid = true;
453
454 query.append(_FINDER_COLUMN_UUID_UUID_2);
455 }
456
457 if (orderByComparator != null) {
458 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
459
460 if (orderByConditionFields.length > 0) {
461 query.append(WHERE_AND);
462 }
463
464 for (int i = 0; i < orderByConditionFields.length; i++) {
465 query.append(_ORDER_BY_ENTITY_ALIAS);
466 query.append(orderByConditionFields[i]);
467
468 if ((i + 1) < orderByConditionFields.length) {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(WHERE_GREATER_THAN_HAS_NEXT);
471 }
472 else {
473 query.append(WHERE_LESSER_THAN_HAS_NEXT);
474 }
475 }
476 else {
477 if (orderByComparator.isAscending() ^ previous) {
478 query.append(WHERE_GREATER_THAN);
479 }
480 else {
481 query.append(WHERE_LESSER_THAN);
482 }
483 }
484 }
485
486 query.append(ORDER_BY_CLAUSE);
487
488 String[] orderByFields = orderByComparator.getOrderByFields();
489
490 for (int i = 0; i < orderByFields.length; i++) {
491 query.append(_ORDER_BY_ENTITY_ALIAS);
492 query.append(orderByFields[i]);
493
494 if ((i + 1) < orderByFields.length) {
495 if (orderByComparator.isAscending() ^ previous) {
496 query.append(ORDER_BY_ASC_HAS_NEXT);
497 }
498 else {
499 query.append(ORDER_BY_DESC_HAS_NEXT);
500 }
501 }
502 else {
503 if (orderByComparator.isAscending() ^ previous) {
504 query.append(ORDER_BY_ASC);
505 }
506 else {
507 query.append(ORDER_BY_DESC);
508 }
509 }
510 }
511 }
512 else {
513 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
514 }
515
516 String sql = query.toString();
517
518 Query q = session.createQuery(sql);
519
520 q.setFirstResult(0);
521 q.setMaxResults(2);
522
523 QueryPos qPos = QueryPos.getInstance(q);
524
525 if (bindUuid) {
526 qPos.add(uuid);
527 }
528
529 if (orderByComparator != null) {
530 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
531
532 for (Object value : values) {
533 qPos.add(value);
534 }
535 }
536
537 List<AssetCategory> list = q.list();
538
539 if (list.size() == 2) {
540 return list.get(1);
541 }
542 else {
543 return null;
544 }
545 }
546
547
553 @Override
554 public void removeByUuid(String uuid) throws SystemException {
555 for (AssetCategory assetCategory : findByUuid(uuid, QueryUtil.ALL_POS,
556 QueryUtil.ALL_POS, null)) {
557 remove(assetCategory);
558 }
559 }
560
561
568 @Override
569 public int countByUuid(String uuid) throws SystemException {
570 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
571
572 Object[] finderArgs = new Object[] { uuid };
573
574 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
575 this);
576
577 if (count == null) {
578 StringBundler query = new StringBundler(2);
579
580 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
581
582 boolean bindUuid = false;
583
584 if (uuid == null) {
585 query.append(_FINDER_COLUMN_UUID_UUID_1);
586 }
587 else if (uuid.equals(StringPool.BLANK)) {
588 query.append(_FINDER_COLUMN_UUID_UUID_3);
589 }
590 else {
591 bindUuid = true;
592
593 query.append(_FINDER_COLUMN_UUID_UUID_2);
594 }
595
596 String sql = query.toString();
597
598 Session session = null;
599
600 try {
601 session = openSession();
602
603 Query q = session.createQuery(sql);
604
605 QueryPos qPos = QueryPos.getInstance(q);
606
607 if (bindUuid) {
608 qPos.add(uuid);
609 }
610
611 count = (Long)q.uniqueResult();
612
613 FinderCacheUtil.putResult(finderPath, finderArgs, count);
614 }
615 catch (Exception e) {
616 FinderCacheUtil.removeResult(finderPath, finderArgs);
617
618 throw processException(e);
619 }
620 finally {
621 closeSession(session);
622 }
623 }
624
625 return count.intValue();
626 }
627
628 private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetCategory.uuid IS NULL";
629 private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetCategory.uuid = ?";
630 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '')";
631 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
632 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
633 AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
634 new String[] { String.class.getName(), Long.class.getName() },
635 AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
636 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK);
637 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
638 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
639 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
640 new String[] { String.class.getName(), Long.class.getName() });
641
642
651 @Override
652 public AssetCategory findByUUID_G(String uuid, long groupId)
653 throws NoSuchCategoryException, SystemException {
654 AssetCategory assetCategory = fetchByUUID_G(uuid, groupId);
655
656 if (assetCategory == null) {
657 StringBundler msg = new StringBundler(6);
658
659 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
660
661 msg.append("uuid=");
662 msg.append(uuid);
663
664 msg.append(", groupId=");
665 msg.append(groupId);
666
667 msg.append(StringPool.CLOSE_CURLY_BRACE);
668
669 if (_log.isWarnEnabled()) {
670 _log.warn(msg.toString());
671 }
672
673 throw new NoSuchCategoryException(msg.toString());
674 }
675
676 return assetCategory;
677 }
678
679
687 @Override
688 public AssetCategory fetchByUUID_G(String uuid, long groupId)
689 throws SystemException {
690 return fetchByUUID_G(uuid, groupId, true);
691 }
692
693
702 @Override
703 public AssetCategory fetchByUUID_G(String uuid, long groupId,
704 boolean retrieveFromCache) throws SystemException {
705 Object[] finderArgs = new Object[] { uuid, groupId };
706
707 Object result = null;
708
709 if (retrieveFromCache) {
710 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
711 finderArgs, this);
712 }
713
714 if (result instanceof AssetCategory) {
715 AssetCategory assetCategory = (AssetCategory)result;
716
717 if (!Validator.equals(uuid, assetCategory.getUuid()) ||
718 (groupId != assetCategory.getGroupId())) {
719 result = null;
720 }
721 }
722
723 if (result == null) {
724 StringBundler query = new StringBundler(4);
725
726 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
727
728 boolean bindUuid = false;
729
730 if (uuid == null) {
731 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
732 }
733 else if (uuid.equals(StringPool.BLANK)) {
734 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
735 }
736 else {
737 bindUuid = true;
738
739 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
740 }
741
742 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
743
744 String sql = query.toString();
745
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 Query q = session.createQuery(sql);
752
753 QueryPos qPos = QueryPos.getInstance(q);
754
755 if (bindUuid) {
756 qPos.add(uuid);
757 }
758
759 qPos.add(groupId);
760
761 List<AssetCategory> list = q.list();
762
763 if (list.isEmpty()) {
764 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
765 finderArgs, list);
766 }
767 else {
768 AssetCategory assetCategory = list.get(0);
769
770 result = assetCategory;
771
772 cacheResult(assetCategory);
773
774 if ((assetCategory.getUuid() == null) ||
775 !assetCategory.getUuid().equals(uuid) ||
776 (assetCategory.getGroupId() != groupId)) {
777 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
778 finderArgs, assetCategory);
779 }
780 }
781 }
782 catch (Exception e) {
783 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
784 finderArgs);
785
786 throw processException(e);
787 }
788 finally {
789 closeSession(session);
790 }
791 }
792
793 if (result instanceof List<?>) {
794 return null;
795 }
796 else {
797 return (AssetCategory)result;
798 }
799 }
800
801
809 @Override
810 public AssetCategory removeByUUID_G(String uuid, long groupId)
811 throws NoSuchCategoryException, SystemException {
812 AssetCategory assetCategory = findByUUID_G(uuid, groupId);
813
814 return remove(assetCategory);
815 }
816
817
825 @Override
826 public int countByUUID_G(String uuid, long groupId)
827 throws SystemException {
828 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
829
830 Object[] finderArgs = new Object[] { uuid, groupId };
831
832 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
833 this);
834
835 if (count == null) {
836 StringBundler query = new StringBundler(3);
837
838 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
839
840 boolean bindUuid = false;
841
842 if (uuid == null) {
843 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
844 }
845 else if (uuid.equals(StringPool.BLANK)) {
846 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
847 }
848 else {
849 bindUuid = true;
850
851 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
852 }
853
854 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
855
856 String sql = query.toString();
857
858 Session session = null;
859
860 try {
861 session = openSession();
862
863 Query q = session.createQuery(sql);
864
865 QueryPos qPos = QueryPos.getInstance(q);
866
867 if (bindUuid) {
868 qPos.add(uuid);
869 }
870
871 qPos.add(groupId);
872
873 count = (Long)q.uniqueResult();
874
875 FinderCacheUtil.putResult(finderPath, finderArgs, count);
876 }
877 catch (Exception e) {
878 FinderCacheUtil.removeResult(finderPath, finderArgs);
879
880 throw processException(e);
881 }
882 finally {
883 closeSession(session);
884 }
885 }
886
887 return count.intValue();
888 }
889
890 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetCategory.uuid IS NULL AND ";
891 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetCategory.uuid = ? AND ";
892 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '') AND ";
893 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetCategory.groupId = ?";
894 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
895 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
896 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
897 "findByUuid_C",
898 new String[] {
899 String.class.getName(), Long.class.getName(),
900
901 Integer.class.getName(), Integer.class.getName(),
902 OrderByComparator.class.getName()
903 });
904 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
905 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
906 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
907 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
908 "findByUuid_C",
909 new String[] { String.class.getName(), Long.class.getName() },
910 AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
911 AssetCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
912 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
913 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
914 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
915 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
916 new String[] { String.class.getName(), Long.class.getName() });
917
918
926 @Override
927 public List<AssetCategory> findByUuid_C(String uuid, long companyId)
928 throws SystemException {
929 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
930 QueryUtil.ALL_POS, null);
931 }
932
933
947 @Override
948 public List<AssetCategory> findByUuid_C(String uuid, long companyId,
949 int start, int end) throws SystemException {
950 return findByUuid_C(uuid, companyId, start, end, null);
951 }
952
953
968 @Override
969 public List<AssetCategory> findByUuid_C(String uuid, long companyId,
970 int start, int end, OrderByComparator orderByComparator)
971 throws SystemException {
972 boolean pagination = true;
973 FinderPath finderPath = null;
974 Object[] finderArgs = null;
975
976 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
977 (orderByComparator == null)) {
978 pagination = false;
979 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
980 finderArgs = new Object[] { uuid, companyId };
981 }
982 else {
983 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
984 finderArgs = new Object[] {
985 uuid, companyId,
986
987 start, end, orderByComparator
988 };
989 }
990
991 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
992 finderArgs, this);
993
994 if ((list != null) && !list.isEmpty()) {
995 for (AssetCategory assetCategory : list) {
996 if (!Validator.equals(uuid, assetCategory.getUuid()) ||
997 (companyId != assetCategory.getCompanyId())) {
998 list = null;
999
1000 break;
1001 }
1002 }
1003 }
1004
1005 if (list == null) {
1006 StringBundler query = null;
1007
1008 if (orderByComparator != null) {
1009 query = new StringBundler(4 +
1010 (orderByComparator.getOrderByFields().length * 3));
1011 }
1012 else {
1013 query = new StringBundler(4);
1014 }
1015
1016 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1017
1018 boolean bindUuid = false;
1019
1020 if (uuid == null) {
1021 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1022 }
1023 else if (uuid.equals(StringPool.BLANK)) {
1024 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1025 }
1026 else {
1027 bindUuid = true;
1028
1029 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1030 }
1031
1032 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1033
1034 if (orderByComparator != null) {
1035 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1036 orderByComparator);
1037 }
1038 else
1039 if (pagination) {
1040 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1041 }
1042
1043 String sql = query.toString();
1044
1045 Session session = null;
1046
1047 try {
1048 session = openSession();
1049
1050 Query q = session.createQuery(sql);
1051
1052 QueryPos qPos = QueryPos.getInstance(q);
1053
1054 if (bindUuid) {
1055 qPos.add(uuid);
1056 }
1057
1058 qPos.add(companyId);
1059
1060 if (!pagination) {
1061 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1062 start, end, false);
1063
1064 Collections.sort(list);
1065
1066 list = new UnmodifiableList<AssetCategory>(list);
1067 }
1068 else {
1069 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1070 start, end);
1071 }
1072
1073 cacheResult(list);
1074
1075 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1076 }
1077 catch (Exception e) {
1078 FinderCacheUtil.removeResult(finderPath, finderArgs);
1079
1080 throw processException(e);
1081 }
1082 finally {
1083 closeSession(session);
1084 }
1085 }
1086
1087 return list;
1088 }
1089
1090
1100 @Override
1101 public AssetCategory findByUuid_C_First(String uuid, long companyId,
1102 OrderByComparator orderByComparator)
1103 throws NoSuchCategoryException, SystemException {
1104 AssetCategory assetCategory = fetchByUuid_C_First(uuid, companyId,
1105 orderByComparator);
1106
1107 if (assetCategory != null) {
1108 return assetCategory;
1109 }
1110
1111 StringBundler msg = new StringBundler(6);
1112
1113 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1114
1115 msg.append("uuid=");
1116 msg.append(uuid);
1117
1118 msg.append(", companyId=");
1119 msg.append(companyId);
1120
1121 msg.append(StringPool.CLOSE_CURLY_BRACE);
1122
1123 throw new NoSuchCategoryException(msg.toString());
1124 }
1125
1126
1135 @Override
1136 public AssetCategory fetchByUuid_C_First(String uuid, long companyId,
1137 OrderByComparator orderByComparator) throws SystemException {
1138 List<AssetCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1139 orderByComparator);
1140
1141 if (!list.isEmpty()) {
1142 return list.get(0);
1143 }
1144
1145 return null;
1146 }
1147
1148
1158 @Override
1159 public AssetCategory findByUuid_C_Last(String uuid, long companyId,
1160 OrderByComparator orderByComparator)
1161 throws NoSuchCategoryException, SystemException {
1162 AssetCategory assetCategory = fetchByUuid_C_Last(uuid, companyId,
1163 orderByComparator);
1164
1165 if (assetCategory != null) {
1166 return assetCategory;
1167 }
1168
1169 StringBundler msg = new StringBundler(6);
1170
1171 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1172
1173 msg.append("uuid=");
1174 msg.append(uuid);
1175
1176 msg.append(", companyId=");
1177 msg.append(companyId);
1178
1179 msg.append(StringPool.CLOSE_CURLY_BRACE);
1180
1181 throw new NoSuchCategoryException(msg.toString());
1182 }
1183
1184
1193 @Override
1194 public AssetCategory fetchByUuid_C_Last(String uuid, long companyId,
1195 OrderByComparator orderByComparator) throws SystemException {
1196 int count = countByUuid_C(uuid, companyId);
1197
1198 if (count == 0) {
1199 return null;
1200 }
1201
1202 List<AssetCategory> list = findByUuid_C(uuid, companyId, count - 1,
1203 count, orderByComparator);
1204
1205 if (!list.isEmpty()) {
1206 return list.get(0);
1207 }
1208
1209 return null;
1210 }
1211
1212
1223 @Override
1224 public AssetCategory[] findByUuid_C_PrevAndNext(long categoryId,
1225 String uuid, long companyId, OrderByComparator orderByComparator)
1226 throws NoSuchCategoryException, SystemException {
1227 AssetCategory assetCategory = findByPrimaryKey(categoryId);
1228
1229 Session session = null;
1230
1231 try {
1232 session = openSession();
1233
1234 AssetCategory[] array = new AssetCategoryImpl[3];
1235
1236 array[0] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1237 companyId, orderByComparator, true);
1238
1239 array[1] = assetCategory;
1240
1241 array[2] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1242 companyId, orderByComparator, false);
1243
1244 return array;
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 closeSession(session);
1251 }
1252 }
1253
1254 protected AssetCategory getByUuid_C_PrevAndNext(Session session,
1255 AssetCategory assetCategory, String uuid, long companyId,
1256 OrderByComparator orderByComparator, boolean previous) {
1257 StringBundler query = null;
1258
1259 if (orderByComparator != null) {
1260 query = new StringBundler(6 +
1261 (orderByComparator.getOrderByFields().length * 6));
1262 }
1263 else {
1264 query = new StringBundler(3);
1265 }
1266
1267 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1268
1269 boolean bindUuid = false;
1270
1271 if (uuid == null) {
1272 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1273 }
1274 else if (uuid.equals(StringPool.BLANK)) {
1275 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1276 }
1277 else {
1278 bindUuid = true;
1279
1280 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1281 }
1282
1283 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1284
1285 if (orderByComparator != null) {
1286 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1287
1288 if (orderByConditionFields.length > 0) {
1289 query.append(WHERE_AND);
1290 }
1291
1292 for (int i = 0; i < orderByConditionFields.length; i++) {
1293 query.append(_ORDER_BY_ENTITY_ALIAS);
1294 query.append(orderByConditionFields[i]);
1295
1296 if ((i + 1) < orderByConditionFields.length) {
1297 if (orderByComparator.isAscending() ^ previous) {
1298 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1299 }
1300 else {
1301 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1302 }
1303 }
1304 else {
1305 if (orderByComparator.isAscending() ^ previous) {
1306 query.append(WHERE_GREATER_THAN);
1307 }
1308 else {
1309 query.append(WHERE_LESSER_THAN);
1310 }
1311 }
1312 }
1313
1314 query.append(ORDER_BY_CLAUSE);
1315
1316 String[] orderByFields = orderByComparator.getOrderByFields();
1317
1318 for (int i = 0; i < orderByFields.length; i++) {
1319 query.append(_ORDER_BY_ENTITY_ALIAS);
1320 query.append(orderByFields[i]);
1321
1322 if ((i + 1) < orderByFields.length) {
1323 if (orderByComparator.isAscending() ^ previous) {
1324 query.append(ORDER_BY_ASC_HAS_NEXT);
1325 }
1326 else {
1327 query.append(ORDER_BY_DESC_HAS_NEXT);
1328 }
1329 }
1330 else {
1331 if (orderByComparator.isAscending() ^ previous) {
1332 query.append(ORDER_BY_ASC);
1333 }
1334 else {
1335 query.append(ORDER_BY_DESC);
1336 }
1337 }
1338 }
1339 }
1340 else {
1341 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1342 }
1343
1344 String sql = query.toString();
1345
1346 Query q = session.createQuery(sql);
1347
1348 q.setFirstResult(0);
1349 q.setMaxResults(2);
1350
1351 QueryPos qPos = QueryPos.getInstance(q);
1352
1353 if (bindUuid) {
1354 qPos.add(uuid);
1355 }
1356
1357 qPos.add(companyId);
1358
1359 if (orderByComparator != null) {
1360 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1361
1362 for (Object value : values) {
1363 qPos.add(value);
1364 }
1365 }
1366
1367 List<AssetCategory> list = q.list();
1368
1369 if (list.size() == 2) {
1370 return list.get(1);
1371 }
1372 else {
1373 return null;
1374 }
1375 }
1376
1377
1384 @Override
1385 public void removeByUuid_C(String uuid, long companyId)
1386 throws SystemException {
1387 for (AssetCategory assetCategory : findByUuid_C(uuid, companyId,
1388 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1389 remove(assetCategory);
1390 }
1391 }
1392
1393
1401 @Override
1402 public int countByUuid_C(String uuid, long companyId)
1403 throws SystemException {
1404 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1405
1406 Object[] finderArgs = new Object[] { uuid, companyId };
1407
1408 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1409 this);
1410
1411 if (count == null) {
1412 StringBundler query = new StringBundler(3);
1413
1414 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
1415
1416 boolean bindUuid = false;
1417
1418 if (uuid == null) {
1419 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1420 }
1421 else if (uuid.equals(StringPool.BLANK)) {
1422 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1423 }
1424 else {
1425 bindUuid = true;
1426
1427 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1428 }
1429
1430 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1431
1432 String sql = query.toString();
1433
1434 Session session = null;
1435
1436 try {
1437 session = openSession();
1438
1439 Query q = session.createQuery(sql);
1440
1441 QueryPos qPos = QueryPos.getInstance(q);
1442
1443 if (bindUuid) {
1444 qPos.add(uuid);
1445 }
1446
1447 qPos.add(companyId);
1448
1449 count = (Long)q.uniqueResult();
1450
1451 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1452 }
1453 catch (Exception e) {
1454 FinderCacheUtil.removeResult(finderPath, finderArgs);
1455
1456 throw processException(e);
1457 }
1458 finally {
1459 closeSession(session);
1460 }
1461 }
1462
1463 return count.intValue();
1464 }
1465
1466 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "assetCategory.uuid IS NULL AND ";
1467 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "assetCategory.uuid = ? AND ";
1468 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '') AND ";
1469 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "assetCategory.companyId = ?";
1470 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1471 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1472 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1473 "findByGroupId",
1474 new String[] {
1475 Long.class.getName(),
1476
1477 Integer.class.getName(), Integer.class.getName(),
1478 OrderByComparator.class.getName()
1479 });
1480 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1481 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1482 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1483 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1484 "findByGroupId", new String[] { Long.class.getName() },
1485 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1486 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
1487 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1488 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1489 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1490 new String[] { Long.class.getName() });
1491
1492
1499 @Override
1500 public List<AssetCategory> findByGroupId(long groupId)
1501 throws SystemException {
1502 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1503 }
1504
1505
1518 @Override
1519 public List<AssetCategory> findByGroupId(long groupId, int start, int end)
1520 throws SystemException {
1521 return findByGroupId(groupId, start, end, null);
1522 }
1523
1524
1538 @Override
1539 public List<AssetCategory> findByGroupId(long groupId, int start, int end,
1540 OrderByComparator orderByComparator) throws SystemException {
1541 boolean pagination = true;
1542 FinderPath finderPath = null;
1543 Object[] finderArgs = null;
1544
1545 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1546 (orderByComparator == null)) {
1547 pagination = false;
1548 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1549 finderArgs = new Object[] { groupId };
1550 }
1551 else {
1552 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1553 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1554 }
1555
1556 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
1557 finderArgs, this);
1558
1559 if ((list != null) && !list.isEmpty()) {
1560 for (AssetCategory assetCategory : list) {
1561 if ((groupId != assetCategory.getGroupId())) {
1562 list = null;
1563
1564 break;
1565 }
1566 }
1567 }
1568
1569 if (list == null) {
1570 StringBundler query = null;
1571
1572 if (orderByComparator != null) {
1573 query = new StringBundler(3 +
1574 (orderByComparator.getOrderByFields().length * 3));
1575 }
1576 else {
1577 query = new StringBundler(3);
1578 }
1579
1580 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1581
1582 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1583
1584 if (orderByComparator != null) {
1585 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1586 orderByComparator);
1587 }
1588 else
1589 if (pagination) {
1590 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1591 }
1592
1593 String sql = query.toString();
1594
1595 Session session = null;
1596
1597 try {
1598 session = openSession();
1599
1600 Query q = session.createQuery(sql);
1601
1602 QueryPos qPos = QueryPos.getInstance(q);
1603
1604 qPos.add(groupId);
1605
1606 if (!pagination) {
1607 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1608 start, end, false);
1609
1610 Collections.sort(list);
1611
1612 list = new UnmodifiableList<AssetCategory>(list);
1613 }
1614 else {
1615 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1616 start, end);
1617 }
1618
1619 cacheResult(list);
1620
1621 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1622 }
1623 catch (Exception e) {
1624 FinderCacheUtil.removeResult(finderPath, finderArgs);
1625
1626 throw processException(e);
1627 }
1628 finally {
1629 closeSession(session);
1630 }
1631 }
1632
1633 return list;
1634 }
1635
1636
1645 @Override
1646 public AssetCategory findByGroupId_First(long groupId,
1647 OrderByComparator orderByComparator)
1648 throws NoSuchCategoryException, SystemException {
1649 AssetCategory assetCategory = fetchByGroupId_First(groupId,
1650 orderByComparator);
1651
1652 if (assetCategory != null) {
1653 return assetCategory;
1654 }
1655
1656 StringBundler msg = new StringBundler(4);
1657
1658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1659
1660 msg.append("groupId=");
1661 msg.append(groupId);
1662
1663 msg.append(StringPool.CLOSE_CURLY_BRACE);
1664
1665 throw new NoSuchCategoryException(msg.toString());
1666 }
1667
1668
1676 @Override
1677 public AssetCategory fetchByGroupId_First(long groupId,
1678 OrderByComparator orderByComparator) throws SystemException {
1679 List<AssetCategory> list = findByGroupId(groupId, 0, 1,
1680 orderByComparator);
1681
1682 if (!list.isEmpty()) {
1683 return list.get(0);
1684 }
1685
1686 return null;
1687 }
1688
1689
1698 @Override
1699 public AssetCategory findByGroupId_Last(long groupId,
1700 OrderByComparator orderByComparator)
1701 throws NoSuchCategoryException, SystemException {
1702 AssetCategory assetCategory = fetchByGroupId_Last(groupId,
1703 orderByComparator);
1704
1705 if (assetCategory != null) {
1706 return assetCategory;
1707 }
1708
1709 StringBundler msg = new StringBundler(4);
1710
1711 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1712
1713 msg.append("groupId=");
1714 msg.append(groupId);
1715
1716 msg.append(StringPool.CLOSE_CURLY_BRACE);
1717
1718 throw new NoSuchCategoryException(msg.toString());
1719 }
1720
1721
1729 @Override
1730 public AssetCategory fetchByGroupId_Last(long groupId,
1731 OrderByComparator orderByComparator) throws SystemException {
1732 int count = countByGroupId(groupId);
1733
1734 if (count == 0) {
1735 return null;
1736 }
1737
1738 List<AssetCategory> list = findByGroupId(groupId, count - 1, count,
1739 orderByComparator);
1740
1741 if (!list.isEmpty()) {
1742 return list.get(0);
1743 }
1744
1745 return null;
1746 }
1747
1748
1758 @Override
1759 public AssetCategory[] findByGroupId_PrevAndNext(long categoryId,
1760 long groupId, OrderByComparator orderByComparator)
1761 throws NoSuchCategoryException, SystemException {
1762 AssetCategory assetCategory = findByPrimaryKey(categoryId);
1763
1764 Session session = null;
1765
1766 try {
1767 session = openSession();
1768
1769 AssetCategory[] array = new AssetCategoryImpl[3];
1770
1771 array[0] = getByGroupId_PrevAndNext(session, assetCategory,
1772 groupId, orderByComparator, true);
1773
1774 array[1] = assetCategory;
1775
1776 array[2] = getByGroupId_PrevAndNext(session, assetCategory,
1777 groupId, orderByComparator, false);
1778
1779 return array;
1780 }
1781 catch (Exception e) {
1782 throw processException(e);
1783 }
1784 finally {
1785 closeSession(session);
1786 }
1787 }
1788
1789 protected AssetCategory getByGroupId_PrevAndNext(Session session,
1790 AssetCategory assetCategory, long groupId,
1791 OrderByComparator orderByComparator, boolean previous) {
1792 StringBundler query = null;
1793
1794 if (orderByComparator != null) {
1795 query = new StringBundler(6 +
1796 (orderByComparator.getOrderByFields().length * 6));
1797 }
1798 else {
1799 query = new StringBundler(3);
1800 }
1801
1802 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1803
1804 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1805
1806 if (orderByComparator != null) {
1807 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1808
1809 if (orderByConditionFields.length > 0) {
1810 query.append(WHERE_AND);
1811 }
1812
1813 for (int i = 0; i < orderByConditionFields.length; i++) {
1814 query.append(_ORDER_BY_ENTITY_ALIAS);
1815 query.append(orderByConditionFields[i]);
1816
1817 if ((i + 1) < orderByConditionFields.length) {
1818 if (orderByComparator.isAscending() ^ previous) {
1819 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1820 }
1821 else {
1822 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1823 }
1824 }
1825 else {
1826 if (orderByComparator.isAscending() ^ previous) {
1827 query.append(WHERE_GREATER_THAN);
1828 }
1829 else {
1830 query.append(WHERE_LESSER_THAN);
1831 }
1832 }
1833 }
1834
1835 query.append(ORDER_BY_CLAUSE);
1836
1837 String[] orderByFields = orderByComparator.getOrderByFields();
1838
1839 for (int i = 0; i < orderByFields.length; i++) {
1840 query.append(_ORDER_BY_ENTITY_ALIAS);
1841 query.append(orderByFields[i]);
1842
1843 if ((i + 1) < orderByFields.length) {
1844 if (orderByComparator.isAscending() ^ previous) {
1845 query.append(ORDER_BY_ASC_HAS_NEXT);
1846 }
1847 else {
1848 query.append(ORDER_BY_DESC_HAS_NEXT);
1849 }
1850 }
1851 else {
1852 if (orderByComparator.isAscending() ^ previous) {
1853 query.append(ORDER_BY_ASC);
1854 }
1855 else {
1856 query.append(ORDER_BY_DESC);
1857 }
1858 }
1859 }
1860 }
1861 else {
1862 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1863 }
1864
1865 String sql = query.toString();
1866
1867 Query q = session.createQuery(sql);
1868
1869 q.setFirstResult(0);
1870 q.setMaxResults(2);
1871
1872 QueryPos qPos = QueryPos.getInstance(q);
1873
1874 qPos.add(groupId);
1875
1876 if (orderByComparator != null) {
1877 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1878
1879 for (Object value : values) {
1880 qPos.add(value);
1881 }
1882 }
1883
1884 List<AssetCategory> list = q.list();
1885
1886 if (list.size() == 2) {
1887 return list.get(1);
1888 }
1889 else {
1890 return null;
1891 }
1892 }
1893
1894
1901 @Override
1902 public List<AssetCategory> filterFindByGroupId(long groupId)
1903 throws SystemException {
1904 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1905 QueryUtil.ALL_POS, null);
1906 }
1907
1908
1921 @Override
1922 public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1923 int end) throws SystemException {
1924 return filterFindByGroupId(groupId, start, end, null);
1925 }
1926
1927
1941 @Override
1942 public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1943 int end, OrderByComparator orderByComparator) throws SystemException {
1944 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1945 return findByGroupId(groupId, start, end, orderByComparator);
1946 }
1947
1948 StringBundler query = null;
1949
1950 if (orderByComparator != null) {
1951 query = new StringBundler(3 +
1952 (orderByComparator.getOrderByFields().length * 3));
1953 }
1954 else {
1955 query = new StringBundler(3);
1956 }
1957
1958 if (getDB().isSupportsInlineDistinct()) {
1959 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
1960 }
1961 else {
1962 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1963 }
1964
1965 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1966
1967 if (!getDB().isSupportsInlineDistinct()) {
1968 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1969 }
1970
1971 if (orderByComparator != null) {
1972 if (getDB().isSupportsInlineDistinct()) {
1973 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1974 orderByComparator, true);
1975 }
1976 else {
1977 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1978 orderByComparator, true);
1979 }
1980 }
1981 else {
1982 if (getDB().isSupportsInlineDistinct()) {
1983 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1984 }
1985 else {
1986 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
1987 }
1988 }
1989
1990 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1991 AssetCategory.class.getName(),
1992 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1993
1994 Session session = null;
1995
1996 try {
1997 session = openSession();
1998
1999 SQLQuery q = session.createSQLQuery(sql);
2000
2001 if (getDB().isSupportsInlineDistinct()) {
2002 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
2003 }
2004 else {
2005 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
2006 }
2007
2008 QueryPos qPos = QueryPos.getInstance(q);
2009
2010 qPos.add(groupId);
2011
2012 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
2013 end);
2014 }
2015 catch (Exception e) {
2016 throw processException(e);
2017 }
2018 finally {
2019 closeSession(session);
2020 }
2021 }
2022
2023
2033 @Override
2034 public AssetCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
2035 long groupId, OrderByComparator orderByComparator)
2036 throws NoSuchCategoryException, SystemException {
2037 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2038 return findByGroupId_PrevAndNext(categoryId, groupId,
2039 orderByComparator);
2040 }
2041
2042 AssetCategory assetCategory = findByPrimaryKey(categoryId);
2043
2044 Session session = null;
2045
2046 try {
2047 session = openSession();
2048
2049 AssetCategory[] array = new AssetCategoryImpl[3];
2050
2051 array[0] = filterGetByGroupId_PrevAndNext(session, assetCategory,
2052 groupId, orderByComparator, true);
2053
2054 array[1] = assetCategory;
2055
2056 array[2] = filterGetByGroupId_PrevAndNext(session, assetCategory,
2057 groupId, orderByComparator, false);
2058
2059 return array;
2060 }
2061 catch (Exception e) {
2062 throw processException(e);
2063 }
2064 finally {
2065 closeSession(session);
2066 }
2067 }
2068
2069 protected AssetCategory filterGetByGroupId_PrevAndNext(Session session,
2070 AssetCategory assetCategory, long groupId,
2071 OrderByComparator orderByComparator, boolean previous) {
2072 StringBundler query = null;
2073
2074 if (orderByComparator != null) {
2075 query = new StringBundler(6 +
2076 (orderByComparator.getOrderByFields().length * 6));
2077 }
2078 else {
2079 query = new StringBundler(3);
2080 }
2081
2082 if (getDB().isSupportsInlineDistinct()) {
2083 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
2084 }
2085 else {
2086 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2087 }
2088
2089 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2090
2091 if (!getDB().isSupportsInlineDistinct()) {
2092 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2093 }
2094
2095 if (orderByComparator != null) {
2096 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2097
2098 if (orderByConditionFields.length > 0) {
2099 query.append(WHERE_AND);
2100 }
2101
2102 for (int i = 0; i < orderByConditionFields.length; i++) {
2103 if (getDB().isSupportsInlineDistinct()) {
2104 query.append(_ORDER_BY_ENTITY_ALIAS);
2105 }
2106 else {
2107 query.append(_ORDER_BY_ENTITY_TABLE);
2108 }
2109
2110 query.append(orderByConditionFields[i]);
2111
2112 if ((i + 1) < orderByConditionFields.length) {
2113 if (orderByComparator.isAscending() ^ previous) {
2114 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2115 }
2116 else {
2117 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2118 }
2119 }
2120 else {
2121 if (orderByComparator.isAscending() ^ previous) {
2122 query.append(WHERE_GREATER_THAN);
2123 }
2124 else {
2125 query.append(WHERE_LESSER_THAN);
2126 }
2127 }
2128 }
2129
2130 query.append(ORDER_BY_CLAUSE);
2131
2132 String[] orderByFields = orderByComparator.getOrderByFields();
2133
2134 for (int i = 0; i < orderByFields.length; i++) {
2135 if (getDB().isSupportsInlineDistinct()) {
2136 query.append(_ORDER_BY_ENTITY_ALIAS);
2137 }
2138 else {
2139 query.append(_ORDER_BY_ENTITY_TABLE);
2140 }
2141
2142 query.append(orderByFields[i]);
2143
2144 if ((i + 1) < orderByFields.length) {
2145 if (orderByComparator.isAscending() ^ previous) {
2146 query.append(ORDER_BY_ASC_HAS_NEXT);
2147 }
2148 else {
2149 query.append(ORDER_BY_DESC_HAS_NEXT);
2150 }
2151 }
2152 else {
2153 if (orderByComparator.isAscending() ^ previous) {
2154 query.append(ORDER_BY_ASC);
2155 }
2156 else {
2157 query.append(ORDER_BY_DESC);
2158 }
2159 }
2160 }
2161 }
2162 else {
2163 if (getDB().isSupportsInlineDistinct()) {
2164 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2165 }
2166 else {
2167 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
2168 }
2169 }
2170
2171 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2172 AssetCategory.class.getName(),
2173 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2174
2175 SQLQuery q = session.createSQLQuery(sql);
2176
2177 q.setFirstResult(0);
2178 q.setMaxResults(2);
2179
2180 if (getDB().isSupportsInlineDistinct()) {
2181 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
2182 }
2183 else {
2184 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
2185 }
2186
2187 QueryPos qPos = QueryPos.getInstance(q);
2188
2189 qPos.add(groupId);
2190
2191 if (orderByComparator != null) {
2192 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2193
2194 for (Object value : values) {
2195 qPos.add(value);
2196 }
2197 }
2198
2199 List<AssetCategory> list = q.list();
2200
2201 if (list.size() == 2) {
2202 return list.get(1);
2203 }
2204 else {
2205 return null;
2206 }
2207 }
2208
2209
2215 @Override
2216 public void removeByGroupId(long groupId) throws SystemException {
2217 for (AssetCategory assetCategory : findByGroupId(groupId,
2218 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2219 remove(assetCategory);
2220 }
2221 }
2222
2223
2230 @Override
2231 public int countByGroupId(long groupId) throws SystemException {
2232 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2233
2234 Object[] finderArgs = new Object[] { groupId };
2235
2236 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2237 this);
2238
2239 if (count == null) {
2240 StringBundler query = new StringBundler(2);
2241
2242 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2243
2244 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2245
2246 String sql = query.toString();
2247
2248 Session session = null;
2249
2250 try {
2251 session = openSession();
2252
2253 Query q = session.createQuery(sql);
2254
2255 QueryPos qPos = QueryPos.getInstance(q);
2256
2257 qPos.add(groupId);
2258
2259 count = (Long)q.uniqueResult();
2260
2261 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2262 }
2263 catch (Exception e) {
2264 FinderCacheUtil.removeResult(finderPath, finderArgs);
2265
2266 throw processException(e);
2267 }
2268 finally {
2269 closeSession(session);
2270 }
2271 }
2272
2273 return count.intValue();
2274 }
2275
2276
2283 @Override
2284 public int filterCountByGroupId(long groupId) throws SystemException {
2285 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2286 return countByGroupId(groupId);
2287 }
2288
2289 StringBundler query = new StringBundler(2);
2290
2291 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
2292
2293 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2294
2295 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2296 AssetCategory.class.getName(),
2297 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2298
2299 Session session = null;
2300
2301 try {
2302 session = openSession();
2303
2304 SQLQuery q = session.createSQLQuery(sql);
2305
2306 q.addScalar(COUNT_COLUMN_NAME,
2307 com.liferay.portal.kernel.dao.orm.Type.LONG);
2308
2309 QueryPos qPos = QueryPos.getInstance(q);
2310
2311 qPos.add(groupId);
2312
2313 Long count = (Long)q.uniqueResult();
2314
2315 return count.intValue();
2316 }
2317 catch (Exception e) {
2318 throw processException(e);
2319 }
2320 finally {
2321 closeSession(session);
2322 }
2323 }
2324
2325 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetCategory.groupId = ?";
2326 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID =
2327 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2328 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2329 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2330 "findByParentCategoryId",
2331 new String[] {
2332 Long.class.getName(),
2333
2334 Integer.class.getName(), Integer.class.getName(),
2335 OrderByComparator.class.getName()
2336 });
2337 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID =
2338 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2339 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2340 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2341 "findByParentCategoryId", new String[] { Long.class.getName() },
2342 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2343 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2344 public static final FinderPath FINDER_PATH_COUNT_BY_PARENTCATEGORYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2345 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2346 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2347 "countByParentCategoryId", new String[] { Long.class.getName() });
2348
2349
2356 @Override
2357 public List<AssetCategory> findByParentCategoryId(long parentCategoryId)
2358 throws SystemException {
2359 return findByParentCategoryId(parentCategoryId, QueryUtil.ALL_POS,
2360 QueryUtil.ALL_POS, null);
2361 }
2362
2363
2376 @Override
2377 public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2378 int start, int end) throws SystemException {
2379 return findByParentCategoryId(parentCategoryId, start, end, null);
2380 }
2381
2382
2396 @Override
2397 public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2398 int start, int end, OrderByComparator orderByComparator)
2399 throws SystemException {
2400 boolean pagination = true;
2401 FinderPath finderPath = null;
2402 Object[] finderArgs = null;
2403
2404 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2405 (orderByComparator == null)) {
2406 pagination = false;
2407 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID;
2408 finderArgs = new Object[] { parentCategoryId };
2409 }
2410 else {
2411 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID;
2412 finderArgs = new Object[] {
2413 parentCategoryId,
2414
2415 start, end, orderByComparator
2416 };
2417 }
2418
2419 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
2420 finderArgs, this);
2421
2422 if ((list != null) && !list.isEmpty()) {
2423 for (AssetCategory assetCategory : list) {
2424 if ((parentCategoryId != assetCategory.getParentCategoryId())) {
2425 list = null;
2426
2427 break;
2428 }
2429 }
2430 }
2431
2432 if (list == null) {
2433 StringBundler query = null;
2434
2435 if (orderByComparator != null) {
2436 query = new StringBundler(3 +
2437 (orderByComparator.getOrderByFields().length * 3));
2438 }
2439 else {
2440 query = new StringBundler(3);
2441 }
2442
2443 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2444
2445 query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2446
2447 if (orderByComparator != null) {
2448 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2449 orderByComparator);
2450 }
2451 else
2452 if (pagination) {
2453 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2454 }
2455
2456 String sql = query.toString();
2457
2458 Session session = null;
2459
2460 try {
2461 session = openSession();
2462
2463 Query q = session.createQuery(sql);
2464
2465 QueryPos qPos = QueryPos.getInstance(q);
2466
2467 qPos.add(parentCategoryId);
2468
2469 if (!pagination) {
2470 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2471 start, end, false);
2472
2473 Collections.sort(list);
2474
2475 list = new UnmodifiableList<AssetCategory>(list);
2476 }
2477 else {
2478 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2479 start, end);
2480 }
2481
2482 cacheResult(list);
2483
2484 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2485 }
2486 catch (Exception e) {
2487 FinderCacheUtil.removeResult(finderPath, finderArgs);
2488
2489 throw processException(e);
2490 }
2491 finally {
2492 closeSession(session);
2493 }
2494 }
2495
2496 return list;
2497 }
2498
2499
2508 @Override
2509 public AssetCategory findByParentCategoryId_First(long parentCategoryId,
2510 OrderByComparator orderByComparator)
2511 throws NoSuchCategoryException, SystemException {
2512 AssetCategory assetCategory = fetchByParentCategoryId_First(parentCategoryId,
2513 orderByComparator);
2514
2515 if (assetCategory != null) {
2516 return assetCategory;
2517 }
2518
2519 StringBundler msg = new StringBundler(4);
2520
2521 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2522
2523 msg.append("parentCategoryId=");
2524 msg.append(parentCategoryId);
2525
2526 msg.append(StringPool.CLOSE_CURLY_BRACE);
2527
2528 throw new NoSuchCategoryException(msg.toString());
2529 }
2530
2531
2539 @Override
2540 public AssetCategory fetchByParentCategoryId_First(long parentCategoryId,
2541 OrderByComparator orderByComparator) throws SystemException {
2542 List<AssetCategory> list = findByParentCategoryId(parentCategoryId, 0,
2543 1, orderByComparator);
2544
2545 if (!list.isEmpty()) {
2546 return list.get(0);
2547 }
2548
2549 return null;
2550 }
2551
2552
2561 @Override
2562 public AssetCategory findByParentCategoryId_Last(long parentCategoryId,
2563 OrderByComparator orderByComparator)
2564 throws NoSuchCategoryException, SystemException {
2565 AssetCategory assetCategory = fetchByParentCategoryId_Last(parentCategoryId,
2566 orderByComparator);
2567
2568 if (assetCategory != null) {
2569 return assetCategory;
2570 }
2571
2572 StringBundler msg = new StringBundler(4);
2573
2574 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2575
2576 msg.append("parentCategoryId=");
2577 msg.append(parentCategoryId);
2578
2579 msg.append(StringPool.CLOSE_CURLY_BRACE);
2580
2581 throw new NoSuchCategoryException(msg.toString());
2582 }
2583
2584
2592 @Override
2593 public AssetCategory fetchByParentCategoryId_Last(long parentCategoryId,
2594 OrderByComparator orderByComparator) throws SystemException {
2595 int count = countByParentCategoryId(parentCategoryId);
2596
2597 if (count == 0) {
2598 return null;
2599 }
2600
2601 List<AssetCategory> list = findByParentCategoryId(parentCategoryId,
2602 count - 1, count, orderByComparator);
2603
2604 if (!list.isEmpty()) {
2605 return list.get(0);
2606 }
2607
2608 return null;
2609 }
2610
2611
2621 @Override
2622 public AssetCategory[] findByParentCategoryId_PrevAndNext(long categoryId,
2623 long parentCategoryId, OrderByComparator orderByComparator)
2624 throws NoSuchCategoryException, SystemException {
2625 AssetCategory assetCategory = findByPrimaryKey(categoryId);
2626
2627 Session session = null;
2628
2629 try {
2630 session = openSession();
2631
2632 AssetCategory[] array = new AssetCategoryImpl[3];
2633
2634 array[0] = getByParentCategoryId_PrevAndNext(session,
2635 assetCategory, parentCategoryId, orderByComparator, true);
2636
2637 array[1] = assetCategory;
2638
2639 array[2] = getByParentCategoryId_PrevAndNext(session,
2640 assetCategory, parentCategoryId, orderByComparator, false);
2641
2642 return array;
2643 }
2644 catch (Exception e) {
2645 throw processException(e);
2646 }
2647 finally {
2648 closeSession(session);
2649 }
2650 }
2651
2652 protected AssetCategory getByParentCategoryId_PrevAndNext(Session session,
2653 AssetCategory assetCategory, long parentCategoryId,
2654 OrderByComparator orderByComparator, boolean previous) {
2655 StringBundler query = null;
2656
2657 if (orderByComparator != null) {
2658 query = new StringBundler(6 +
2659 (orderByComparator.getOrderByFields().length * 6));
2660 }
2661 else {
2662 query = new StringBundler(3);
2663 }
2664
2665 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2666
2667 query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2668
2669 if (orderByComparator != null) {
2670 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2671
2672 if (orderByConditionFields.length > 0) {
2673 query.append(WHERE_AND);
2674 }
2675
2676 for (int i = 0; i < orderByConditionFields.length; i++) {
2677 query.append(_ORDER_BY_ENTITY_ALIAS);
2678 query.append(orderByConditionFields[i]);
2679
2680 if ((i + 1) < orderByConditionFields.length) {
2681 if (orderByComparator.isAscending() ^ previous) {
2682 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2683 }
2684 else {
2685 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2686 }
2687 }
2688 else {
2689 if (orderByComparator.isAscending() ^ previous) {
2690 query.append(WHERE_GREATER_THAN);
2691 }
2692 else {
2693 query.append(WHERE_LESSER_THAN);
2694 }
2695 }
2696 }
2697
2698 query.append(ORDER_BY_CLAUSE);
2699
2700 String[] orderByFields = orderByComparator.getOrderByFields();
2701
2702 for (int i = 0; i < orderByFields.length; i++) {
2703 query.append(_ORDER_BY_ENTITY_ALIAS);
2704 query.append(orderByFields[i]);
2705
2706 if ((i + 1) < orderByFields.length) {
2707 if (orderByComparator.isAscending() ^ previous) {
2708 query.append(ORDER_BY_ASC_HAS_NEXT);
2709 }
2710 else {
2711 query.append(ORDER_BY_DESC_HAS_NEXT);
2712 }
2713 }
2714 else {
2715 if (orderByComparator.isAscending() ^ previous) {
2716 query.append(ORDER_BY_ASC);
2717 }
2718 else {
2719 query.append(ORDER_BY_DESC);
2720 }
2721 }
2722 }
2723 }
2724 else {
2725 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2726 }
2727
2728 String sql = query.toString();
2729
2730 Query q = session.createQuery(sql);
2731
2732 q.setFirstResult(0);
2733 q.setMaxResults(2);
2734
2735 QueryPos qPos = QueryPos.getInstance(q);
2736
2737 qPos.add(parentCategoryId);
2738
2739 if (orderByComparator != null) {
2740 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2741
2742 for (Object value : values) {
2743 qPos.add(value);
2744 }
2745 }
2746
2747 List<AssetCategory> list = q.list();
2748
2749 if (list.size() == 2) {
2750 return list.get(1);
2751 }
2752 else {
2753 return null;
2754 }
2755 }
2756
2757
2763 @Override
2764 public void removeByParentCategoryId(long parentCategoryId)
2765 throws SystemException {
2766 for (AssetCategory assetCategory : findByParentCategoryId(
2767 parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2768 remove(assetCategory);
2769 }
2770 }
2771
2772
2779 @Override
2780 public int countByParentCategoryId(long parentCategoryId)
2781 throws SystemException {
2782 FinderPath finderPath = FINDER_PATH_COUNT_BY_PARENTCATEGORYID;
2783
2784 Object[] finderArgs = new Object[] { parentCategoryId };
2785
2786 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2787 this);
2788
2789 if (count == null) {
2790 StringBundler query = new StringBundler(2);
2791
2792 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2793
2794 query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2795
2796 String sql = query.toString();
2797
2798 Session session = null;
2799
2800 try {
2801 session = openSession();
2802
2803 Query q = session.createQuery(sql);
2804
2805 QueryPos qPos = QueryPos.getInstance(q);
2806
2807 qPos.add(parentCategoryId);
2808
2809 count = (Long)q.uniqueResult();
2810
2811 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2812 }
2813 catch (Exception e) {
2814 FinderCacheUtil.removeResult(finderPath, finderArgs);
2815
2816 throw processException(e);
2817 }
2818 finally {
2819 closeSession(session);
2820 }
2821 }
2822
2823 return count.intValue();
2824 }
2825
2826 private static final String _FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2 =
2827 "assetCategory.parentCategoryId = ?";
2828 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID =
2829 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2830 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2831 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2832 "findByVocabularyId",
2833 new String[] {
2834 Long.class.getName(),
2835
2836 Integer.class.getName(), Integer.class.getName(),
2837 OrderByComparator.class.getName()
2838 });
2839 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID =
2840 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2841 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2842 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2843 "findByVocabularyId", new String[] { Long.class.getName() },
2844 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
2845 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2846 public static final FinderPath FINDER_PATH_COUNT_BY_VOCABULARYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2847 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2848 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVocabularyId",
2849 new String[] { Long.class.getName() });
2850
2851
2858 @Override
2859 public List<AssetCategory> findByVocabularyId(long vocabularyId)
2860 throws SystemException {
2861 return findByVocabularyId(vocabularyId, QueryUtil.ALL_POS,
2862 QueryUtil.ALL_POS, null);
2863 }
2864
2865
2878 @Override
2879 public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2880 int end) throws SystemException {
2881 return findByVocabularyId(vocabularyId, start, end, null);
2882 }
2883
2884
2898 @Override
2899 public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2900 int end, OrderByComparator orderByComparator) throws SystemException {
2901 boolean pagination = true;
2902 FinderPath finderPath = null;
2903 Object[] finderArgs = null;
2904
2905 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2906 (orderByComparator == null)) {
2907 pagination = false;
2908 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID;
2909 finderArgs = new Object[] { vocabularyId };
2910 }
2911 else {
2912 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID;
2913 finderArgs = new Object[] {
2914 vocabularyId,
2915
2916 start, end, orderByComparator
2917 };
2918 }
2919
2920 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
2921 finderArgs, this);
2922
2923 if ((list != null) && !list.isEmpty()) {
2924 for (AssetCategory assetCategory : list) {
2925 if ((vocabularyId != assetCategory.getVocabularyId())) {
2926 list = null;
2927
2928 break;
2929 }
2930 }
2931 }
2932
2933 if (list == null) {
2934 StringBundler query = null;
2935
2936 if (orderByComparator != null) {
2937 query = new StringBundler(3 +
2938 (orderByComparator.getOrderByFields().length * 3));
2939 }
2940 else {
2941 query = new StringBundler(3);
2942 }
2943
2944 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2945
2946 query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
2947
2948 if (orderByComparator != null) {
2949 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2950 orderByComparator);
2951 }
2952 else
2953 if (pagination) {
2954 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2955 }
2956
2957 String sql = query.toString();
2958
2959 Session session = null;
2960
2961 try {
2962 session = openSession();
2963
2964 Query q = session.createQuery(sql);
2965
2966 QueryPos qPos = QueryPos.getInstance(q);
2967
2968 qPos.add(vocabularyId);
2969
2970 if (!pagination) {
2971 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2972 start, end, false);
2973
2974 Collections.sort(list);
2975
2976 list = new UnmodifiableList<AssetCategory>(list);
2977 }
2978 else {
2979 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2980 start, end);
2981 }
2982
2983 cacheResult(list);
2984
2985 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2986 }
2987 catch (Exception e) {
2988 FinderCacheUtil.removeResult(finderPath, finderArgs);
2989
2990 throw processException(e);
2991 }
2992 finally {
2993 closeSession(session);
2994 }
2995 }
2996
2997 return list;
2998 }
2999
3000
3009 @Override
3010 public AssetCategory findByVocabularyId_First(long vocabularyId,
3011 OrderByComparator orderByComparator)
3012 throws NoSuchCategoryException, SystemException {
3013 AssetCategory assetCategory = fetchByVocabularyId_First(vocabularyId,
3014 orderByComparator);
3015
3016 if (assetCategory != null) {
3017 return assetCategory;
3018 }
3019
3020 StringBundler msg = new StringBundler(4);
3021
3022 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3023
3024 msg.append("vocabularyId=");
3025 msg.append(vocabularyId);
3026
3027 msg.append(StringPool.CLOSE_CURLY_BRACE);
3028
3029 throw new NoSuchCategoryException(msg.toString());
3030 }
3031
3032
3040 @Override
3041 public AssetCategory fetchByVocabularyId_First(long vocabularyId,
3042 OrderByComparator orderByComparator) throws SystemException {
3043 List<AssetCategory> list = findByVocabularyId(vocabularyId, 0, 1,
3044 orderByComparator);
3045
3046 if (!list.isEmpty()) {
3047 return list.get(0);
3048 }
3049
3050 return null;
3051 }
3052
3053
3062 @Override
3063 public AssetCategory findByVocabularyId_Last(long vocabularyId,
3064 OrderByComparator orderByComparator)
3065 throws NoSuchCategoryException, SystemException {
3066 AssetCategory assetCategory = fetchByVocabularyId_Last(vocabularyId,
3067 orderByComparator);
3068
3069 if (assetCategory != null) {
3070 return assetCategory;
3071 }
3072
3073 StringBundler msg = new StringBundler(4);
3074
3075 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3076
3077 msg.append("vocabularyId=");
3078 msg.append(vocabularyId);
3079
3080 msg.append(StringPool.CLOSE_CURLY_BRACE);
3081
3082 throw new NoSuchCategoryException(msg.toString());
3083 }
3084
3085
3093 @Override
3094 public AssetCategory fetchByVocabularyId_Last(long vocabularyId,
3095 OrderByComparator orderByComparator) throws SystemException {
3096 int count = countByVocabularyId(vocabularyId);
3097
3098 if (count == 0) {
3099 return null;
3100 }
3101
3102 List<AssetCategory> list = findByVocabularyId(vocabularyId, count - 1,
3103 count, orderByComparator);
3104
3105 if (!list.isEmpty()) {
3106 return list.get(0);
3107 }
3108
3109 return null;
3110 }
3111
3112
3122 @Override
3123 public AssetCategory[] findByVocabularyId_PrevAndNext(long categoryId,
3124 long vocabularyId, OrderByComparator orderByComparator)
3125 throws NoSuchCategoryException, SystemException {
3126 AssetCategory assetCategory = findByPrimaryKey(categoryId);
3127
3128 Session session = null;
3129
3130 try {
3131 session = openSession();
3132
3133 AssetCategory[] array = new AssetCategoryImpl[3];
3134
3135 array[0] = getByVocabularyId_PrevAndNext(session, assetCategory,
3136 vocabularyId, orderByComparator, true);
3137
3138 array[1] = assetCategory;
3139
3140 array[2] = getByVocabularyId_PrevAndNext(session, assetCategory,
3141 vocabularyId, orderByComparator, false);
3142
3143 return array;
3144 }
3145 catch (Exception e) {
3146 throw processException(e);
3147 }
3148 finally {
3149 closeSession(session);
3150 }
3151 }
3152
3153 protected AssetCategory getByVocabularyId_PrevAndNext(Session session,
3154 AssetCategory assetCategory, long vocabularyId,
3155 OrderByComparator orderByComparator, boolean previous) {
3156 StringBundler query = null;
3157
3158 if (orderByComparator != null) {
3159 query = new StringBundler(6 +
3160 (orderByComparator.getOrderByFields().length * 6));
3161 }
3162 else {
3163 query = new StringBundler(3);
3164 }
3165
3166 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3167
3168 query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3169
3170 if (orderByComparator != null) {
3171 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3172
3173 if (orderByConditionFields.length > 0) {
3174 query.append(WHERE_AND);
3175 }
3176
3177 for (int i = 0; i < orderByConditionFields.length; i++) {
3178 query.append(_ORDER_BY_ENTITY_ALIAS);
3179 query.append(orderByConditionFields[i]);
3180
3181 if ((i + 1) < orderByConditionFields.length) {
3182 if (orderByComparator.isAscending() ^ previous) {
3183 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3184 }
3185 else {
3186 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3187 }
3188 }
3189 else {
3190 if (orderByComparator.isAscending() ^ previous) {
3191 query.append(WHERE_GREATER_THAN);
3192 }
3193 else {
3194 query.append(WHERE_LESSER_THAN);
3195 }
3196 }
3197 }
3198
3199 query.append(ORDER_BY_CLAUSE);
3200
3201 String[] orderByFields = orderByComparator.getOrderByFields();
3202
3203 for (int i = 0; i < orderByFields.length; i++) {
3204 query.append(_ORDER_BY_ENTITY_ALIAS);
3205 query.append(orderByFields[i]);
3206
3207 if ((i + 1) < orderByFields.length) {
3208 if (orderByComparator.isAscending() ^ previous) {
3209 query.append(ORDER_BY_ASC_HAS_NEXT);
3210 }
3211 else {
3212 query.append(ORDER_BY_DESC_HAS_NEXT);
3213 }
3214 }
3215 else {
3216 if (orderByComparator.isAscending() ^ previous) {
3217 query.append(ORDER_BY_ASC);
3218 }
3219 else {
3220 query.append(ORDER_BY_DESC);
3221 }
3222 }
3223 }
3224 }
3225 else {
3226 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3227 }
3228
3229 String sql = query.toString();
3230
3231 Query q = session.createQuery(sql);
3232
3233 q.setFirstResult(0);
3234 q.setMaxResults(2);
3235
3236 QueryPos qPos = QueryPos.getInstance(q);
3237
3238 qPos.add(vocabularyId);
3239
3240 if (orderByComparator != null) {
3241 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3242
3243 for (Object value : values) {
3244 qPos.add(value);
3245 }
3246 }
3247
3248 List<AssetCategory> list = q.list();
3249
3250 if (list.size() == 2) {
3251 return list.get(1);
3252 }
3253 else {
3254 return null;
3255 }
3256 }
3257
3258
3264 @Override
3265 public void removeByVocabularyId(long vocabularyId)
3266 throws SystemException {
3267 for (AssetCategory assetCategory : findByVocabularyId(vocabularyId,
3268 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3269 remove(assetCategory);
3270 }
3271 }
3272
3273
3280 @Override
3281 public int countByVocabularyId(long vocabularyId) throws SystemException {
3282 FinderPath finderPath = FINDER_PATH_COUNT_BY_VOCABULARYID;
3283
3284 Object[] finderArgs = new Object[] { vocabularyId };
3285
3286 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3287 this);
3288
3289 if (count == null) {
3290 StringBundler query = new StringBundler(2);
3291
3292 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3293
3294 query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3295
3296 String sql = query.toString();
3297
3298 Session session = null;
3299
3300 try {
3301 session = openSession();
3302
3303 Query q = session.createQuery(sql);
3304
3305 QueryPos qPos = QueryPos.getInstance(q);
3306
3307 qPos.add(vocabularyId);
3308
3309 count = (Long)q.uniqueResult();
3310
3311 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3312 }
3313 catch (Exception e) {
3314 FinderCacheUtil.removeResult(finderPath, finderArgs);
3315
3316 throw processException(e);
3317 }
3318 finally {
3319 closeSession(session);
3320 }
3321 }
3322
3323 return count.intValue();
3324 }
3325
3326 private static final String _FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
3327 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3328 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3329 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3330 "findByG_V",
3331 new String[] {
3332 Long.class.getName(), Long.class.getName(),
3333
3334 Integer.class.getName(), Integer.class.getName(),
3335 OrderByComparator.class.getName()
3336 });
3337 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3338 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3339 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3340 "findByG_V",
3341 new String[] { Long.class.getName(), Long.class.getName() },
3342 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
3343 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
3344 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
3345 public static final FinderPath FINDER_PATH_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3346 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3347 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_V",
3348 new String[] { Long.class.getName(), Long.class.getName() });
3349 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3350 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3351 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_V",
3352 new String[] { Long.class.getName(), Long.class.getName() });
3353
3354
3362 @Override
3363 public List<AssetCategory> findByG_V(long groupId, long vocabularyId)
3364 throws SystemException {
3365 return findByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3366 QueryUtil.ALL_POS, null);
3367 }
3368
3369
3383 @Override
3384 public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3385 int start, int end) throws SystemException {
3386 return findByG_V(groupId, vocabularyId, start, end, null);
3387 }
3388
3389
3404 @Override
3405 public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3406 int start, int end, OrderByComparator orderByComparator)
3407 throws SystemException {
3408 boolean pagination = true;
3409 FinderPath finderPath = null;
3410 Object[] finderArgs = null;
3411
3412 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3413 (orderByComparator == null)) {
3414 pagination = false;
3415 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V;
3416 finderArgs = new Object[] { groupId, vocabularyId };
3417 }
3418 else {
3419 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V;
3420 finderArgs = new Object[] {
3421 groupId, vocabularyId,
3422
3423 start, end, orderByComparator
3424 };
3425 }
3426
3427 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
3428 finderArgs, this);
3429
3430 if ((list != null) && !list.isEmpty()) {
3431 for (AssetCategory assetCategory : list) {
3432 if ((groupId != assetCategory.getGroupId()) ||
3433 (vocabularyId != assetCategory.getVocabularyId())) {
3434 list = null;
3435
3436 break;
3437 }
3438 }
3439 }
3440
3441 if (list == null) {
3442 StringBundler query = null;
3443
3444 if (orderByComparator != null) {
3445 query = new StringBundler(4 +
3446 (orderByComparator.getOrderByFields().length * 3));
3447 }
3448 else {
3449 query = new StringBundler(4);
3450 }
3451
3452 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3453
3454 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3455
3456 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3457
3458 if (orderByComparator != null) {
3459 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3460 orderByComparator);
3461 }
3462 else
3463 if (pagination) {
3464 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3465 }
3466
3467 String sql = query.toString();
3468
3469 Session session = null;
3470
3471 try {
3472 session = openSession();
3473
3474 Query q = session.createQuery(sql);
3475
3476 QueryPos qPos = QueryPos.getInstance(q);
3477
3478 qPos.add(groupId);
3479
3480 qPos.add(vocabularyId);
3481
3482 if (!pagination) {
3483 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3484 start, end, false);
3485
3486 Collections.sort(list);
3487
3488 list = new UnmodifiableList<AssetCategory>(list);
3489 }
3490 else {
3491 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3492 start, end);
3493 }
3494
3495 cacheResult(list);
3496
3497 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3498 }
3499 catch (Exception e) {
3500 FinderCacheUtil.removeResult(finderPath, finderArgs);
3501
3502 throw processException(e);
3503 }
3504 finally {
3505 closeSession(session);
3506 }
3507 }
3508
3509 return list;
3510 }
3511
3512
3522 @Override
3523 public AssetCategory findByG_V_First(long groupId, long vocabularyId,
3524 OrderByComparator orderByComparator)
3525 throws NoSuchCategoryException, SystemException {
3526 AssetCategory assetCategory = fetchByG_V_First(groupId, vocabularyId,
3527 orderByComparator);
3528
3529 if (assetCategory != null) {
3530 return assetCategory;
3531 }
3532
3533 StringBundler msg = new StringBundler(6);
3534
3535 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3536
3537 msg.append("groupId=");
3538 msg.append(groupId);
3539
3540 msg.append(", vocabularyId=");
3541 msg.append(vocabularyId);
3542
3543 msg.append(StringPool.CLOSE_CURLY_BRACE);
3544
3545 throw new NoSuchCategoryException(msg.toString());
3546 }
3547
3548
3557 @Override
3558 public AssetCategory fetchByG_V_First(long groupId, long vocabularyId,
3559 OrderByComparator orderByComparator) throws SystemException {
3560 List<AssetCategory> list = findByG_V(groupId, vocabularyId, 0, 1,
3561 orderByComparator);
3562
3563 if (!list.isEmpty()) {
3564 return list.get(0);
3565 }
3566
3567 return null;
3568 }
3569
3570
3580 @Override
3581 public AssetCategory findByG_V_Last(long groupId, long vocabularyId,
3582 OrderByComparator orderByComparator)
3583 throws NoSuchCategoryException, SystemException {
3584 AssetCategory assetCategory = fetchByG_V_Last(groupId, vocabularyId,
3585 orderByComparator);
3586
3587 if (assetCategory != null) {
3588 return assetCategory;
3589 }
3590
3591 StringBundler msg = new StringBundler(6);
3592
3593 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3594
3595 msg.append("groupId=");
3596 msg.append(groupId);
3597
3598 msg.append(", vocabularyId=");
3599 msg.append(vocabularyId);
3600
3601 msg.append(StringPool.CLOSE_CURLY_BRACE);
3602
3603 throw new NoSuchCategoryException(msg.toString());
3604 }
3605
3606
3615 @Override
3616 public AssetCategory fetchByG_V_Last(long groupId, long vocabularyId,
3617 OrderByComparator orderByComparator) throws SystemException {
3618 int count = countByG_V(groupId, vocabularyId);
3619
3620 if (count == 0) {
3621 return null;
3622 }
3623
3624 List<AssetCategory> list = findByG_V(groupId, vocabularyId, count - 1,
3625 count, orderByComparator);
3626
3627 if (!list.isEmpty()) {
3628 return list.get(0);
3629 }
3630
3631 return null;
3632 }
3633
3634
3645 @Override
3646 public AssetCategory[] findByG_V_PrevAndNext(long categoryId, long groupId,
3647 long vocabularyId, OrderByComparator orderByComparator)
3648 throws NoSuchCategoryException, SystemException {
3649 AssetCategory assetCategory = findByPrimaryKey(categoryId);
3650
3651 Session session = null;
3652
3653 try {
3654 session = openSession();
3655
3656 AssetCategory[] array = new AssetCategoryImpl[3];
3657
3658 array[0] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3659 vocabularyId, orderByComparator, true);
3660
3661 array[1] = assetCategory;
3662
3663 array[2] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3664 vocabularyId, orderByComparator, false);
3665
3666 return array;
3667 }
3668 catch (Exception e) {
3669 throw processException(e);
3670 }
3671 finally {
3672 closeSession(session);
3673 }
3674 }
3675
3676 protected AssetCategory getByG_V_PrevAndNext(Session session,
3677 AssetCategory assetCategory, long groupId, long vocabularyId,
3678 OrderByComparator orderByComparator, boolean previous) {
3679 StringBundler query = null;
3680
3681 if (orderByComparator != null) {
3682 query = new StringBundler(6 +
3683 (orderByComparator.getOrderByFields().length * 6));
3684 }
3685 else {
3686 query = new StringBundler(3);
3687 }
3688
3689 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3690
3691 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3692
3693 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3694
3695 if (orderByComparator != null) {
3696 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3697
3698 if (orderByConditionFields.length > 0) {
3699 query.append(WHERE_AND);
3700 }
3701
3702 for (int i = 0; i < orderByConditionFields.length; i++) {
3703 query.append(_ORDER_BY_ENTITY_ALIAS);
3704 query.append(orderByConditionFields[i]);
3705
3706 if ((i + 1) < orderByConditionFields.length) {
3707 if (orderByComparator.isAscending() ^ previous) {
3708 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3709 }
3710 else {
3711 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3712 }
3713 }
3714 else {
3715 if (orderByComparator.isAscending() ^ previous) {
3716 query.append(WHERE_GREATER_THAN);
3717 }
3718 else {
3719 query.append(WHERE_LESSER_THAN);
3720 }
3721 }
3722 }
3723
3724 query.append(ORDER_BY_CLAUSE);
3725
3726 String[] orderByFields = orderByComparator.getOrderByFields();
3727
3728 for (int i = 0; i < orderByFields.length; i++) {
3729 query.append(_ORDER_BY_ENTITY_ALIAS);
3730 query.append(orderByFields[i]);
3731
3732 if ((i + 1) < orderByFields.length) {
3733 if (orderByComparator.isAscending() ^ previous) {
3734 query.append(ORDER_BY_ASC_HAS_NEXT);
3735 }
3736 else {
3737 query.append(ORDER_BY_DESC_HAS_NEXT);
3738 }
3739 }
3740 else {
3741 if (orderByComparator.isAscending() ^ previous) {
3742 query.append(ORDER_BY_ASC);
3743 }
3744 else {
3745 query.append(ORDER_BY_DESC);
3746 }
3747 }
3748 }
3749 }
3750 else {
3751 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3752 }
3753
3754 String sql = query.toString();
3755
3756 Query q = session.createQuery(sql);
3757
3758 q.setFirstResult(0);
3759 q.setMaxResults(2);
3760
3761 QueryPos qPos = QueryPos.getInstance(q);
3762
3763 qPos.add(groupId);
3764
3765 qPos.add(vocabularyId);
3766
3767 if (orderByComparator != null) {
3768 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3769
3770 for (Object value : values) {
3771 qPos.add(value);
3772 }
3773 }
3774
3775 List<AssetCategory> list = q.list();
3776
3777 if (list.size() == 2) {
3778 return list.get(1);
3779 }
3780 else {
3781 return null;
3782 }
3783 }
3784
3785
3793 @Override
3794 public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId)
3795 throws SystemException {
3796 return filterFindByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3797 QueryUtil.ALL_POS, null);
3798 }
3799
3800
3814 @Override
3815 public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3816 int start, int end) throws SystemException {
3817 return filterFindByG_V(groupId, vocabularyId, start, end, null);
3818 }
3819
3820
3835 @Override
3836 public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3837 int start, int end, OrderByComparator orderByComparator)
3838 throws SystemException {
3839 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3840 return findByG_V(groupId, vocabularyId, start, end,
3841 orderByComparator);
3842 }
3843
3844 StringBundler query = null;
3845
3846 if (orderByComparator != null) {
3847 query = new StringBundler(4 +
3848 (orderByComparator.getOrderByFields().length * 3));
3849 }
3850 else {
3851 query = new StringBundler(4);
3852 }
3853
3854 if (getDB().isSupportsInlineDistinct()) {
3855 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3856 }
3857 else {
3858 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3859 }
3860
3861 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3862
3863 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3864
3865 if (!getDB().isSupportsInlineDistinct()) {
3866 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3867 }
3868
3869 if (orderByComparator != null) {
3870 if (getDB().isSupportsInlineDistinct()) {
3871 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3872 orderByComparator, true);
3873 }
3874 else {
3875 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3876 orderByComparator, true);
3877 }
3878 }
3879 else {
3880 if (getDB().isSupportsInlineDistinct()) {
3881 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3882 }
3883 else {
3884 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
3885 }
3886 }
3887
3888 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3889 AssetCategory.class.getName(),
3890 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3891
3892 Session session = null;
3893
3894 try {
3895 session = openSession();
3896
3897 SQLQuery q = session.createSQLQuery(sql);
3898
3899 if (getDB().isSupportsInlineDistinct()) {
3900 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
3901 }
3902 else {
3903 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
3904 }
3905
3906 QueryPos qPos = QueryPos.getInstance(q);
3907
3908 qPos.add(groupId);
3909
3910 qPos.add(vocabularyId);
3911
3912 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
3913 end);
3914 }
3915 catch (Exception e) {
3916 throw processException(e);
3917 }
3918 finally {
3919 closeSession(session);
3920 }
3921 }
3922
3923
3934 @Override
3935 public AssetCategory[] filterFindByG_V_PrevAndNext(long categoryId,
3936 long groupId, long vocabularyId, OrderByComparator orderByComparator)
3937 throws NoSuchCategoryException, SystemException {
3938 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3939 return findByG_V_PrevAndNext(categoryId, groupId, vocabularyId,
3940 orderByComparator);
3941 }
3942
3943 AssetCategory assetCategory = findByPrimaryKey(categoryId);
3944
3945 Session session = null;
3946
3947 try {
3948 session = openSession();
3949
3950 AssetCategory[] array = new AssetCategoryImpl[3];
3951
3952 array[0] = filterGetByG_V_PrevAndNext(session, assetCategory,
3953 groupId, vocabularyId, orderByComparator, true);
3954
3955 array[1] = assetCategory;
3956
3957 array[2] = filterGetByG_V_PrevAndNext(session, assetCategory,
3958 groupId, vocabularyId, orderByComparator, false);
3959
3960 return array;
3961 }
3962 catch (Exception e) {
3963 throw processException(e);
3964 }
3965 finally {
3966 closeSession(session);
3967 }
3968 }
3969
3970 protected AssetCategory filterGetByG_V_PrevAndNext(Session session,
3971 AssetCategory assetCategory, long groupId, long vocabularyId,
3972 OrderByComparator orderByComparator, boolean previous) {
3973 StringBundler query = null;
3974
3975 if (orderByComparator != null) {
3976 query = new StringBundler(6 +
3977 (orderByComparator.getOrderByFields().length * 6));
3978 }
3979 else {
3980 query = new StringBundler(3);
3981 }
3982
3983 if (getDB().isSupportsInlineDistinct()) {
3984 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3985 }
3986 else {
3987 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3988 }
3989
3990 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3991
3992 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3993
3994 if (!getDB().isSupportsInlineDistinct()) {
3995 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3996 }
3997
3998 if (orderByComparator != null) {
3999 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4000
4001 if (orderByConditionFields.length > 0) {
4002 query.append(WHERE_AND);
4003 }
4004
4005 for (int i = 0; i < orderByConditionFields.length; i++) {
4006 if (getDB().isSupportsInlineDistinct()) {
4007 query.append(_ORDER_BY_ENTITY_ALIAS);
4008 }
4009 else {
4010 query.append(_ORDER_BY_ENTITY_TABLE);
4011 }
4012
4013 query.append(orderByConditionFields[i]);
4014
4015 if ((i + 1) < orderByConditionFields.length) {
4016 if (orderByComparator.isAscending() ^ previous) {
4017 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4018 }
4019 else {
4020 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4021 }
4022 }
4023 else {
4024 if (orderByComparator.isAscending() ^ previous) {
4025 query.append(WHERE_GREATER_THAN);
4026 }
4027 else {
4028 query.append(WHERE_LESSER_THAN);
4029 }
4030 }
4031 }
4032
4033 query.append(ORDER_BY_CLAUSE);
4034
4035 String[] orderByFields = orderByComparator.getOrderByFields();
4036
4037 for (int i = 0; i < orderByFields.length; i++) {
4038 if (getDB().isSupportsInlineDistinct()) {
4039 query.append(_ORDER_BY_ENTITY_ALIAS);
4040 }
4041 else {
4042 query.append(_ORDER_BY_ENTITY_TABLE);
4043 }
4044
4045 query.append(orderByFields[i]);
4046
4047 if ((i + 1) < orderByFields.length) {
4048 if (orderByComparator.isAscending() ^ previous) {
4049 query.append(ORDER_BY_ASC_HAS_NEXT);
4050 }
4051 else {
4052 query.append(ORDER_BY_DESC_HAS_NEXT);
4053 }
4054 }
4055 else {
4056 if (orderByComparator.isAscending() ^ previous) {
4057 query.append(ORDER_BY_ASC);
4058 }
4059 else {
4060 query.append(ORDER_BY_DESC);
4061 }
4062 }
4063 }
4064 }
4065 else {
4066 if (getDB().isSupportsInlineDistinct()) {
4067 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4068 }
4069 else {
4070 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
4071 }
4072 }
4073
4074 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4075 AssetCategory.class.getName(),
4076 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4077
4078 SQLQuery q = session.createSQLQuery(sql);
4079
4080 q.setFirstResult(0);
4081 q.setMaxResults(2);
4082
4083 if (getDB().isSupportsInlineDistinct()) {
4084 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
4085 }
4086 else {
4087 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
4088 }
4089
4090 QueryPos qPos = QueryPos.getInstance(q);
4091
4092 qPos.add(groupId);
4093
4094 qPos.add(vocabularyId);
4095
4096 if (orderByComparator != null) {
4097 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
4098
4099 for (Object value : values) {
4100 qPos.add(value);
4101 }
4102 }
4103
4104 List<AssetCategory> list = q.list();
4105
4106 if (list.size() == 2) {
4107 return list.get(1);
4108 }
4109 else {
4110 return null;
4111 }
4112 }
4113
4114
4122 @Override
4123 public List<AssetCategory> filterFindByG_V(long groupId,
4124 long[] vocabularyIds) throws SystemException {
4125 return filterFindByG_V(groupId, vocabularyIds, QueryUtil.ALL_POS,
4126 QueryUtil.ALL_POS, null);
4127 }
4128
4129
4143 @Override
4144 public List<AssetCategory> filterFindByG_V(long groupId,
4145 long[] vocabularyIds, int start, int end) throws SystemException {
4146 return filterFindByG_V(groupId, vocabularyIds, start, end, null);
4147 }
4148
4149
4164 @Override
4165 public List<AssetCategory> filterFindByG_V(long groupId,
4166 long[] vocabularyIds, int start, int end,
4167 OrderByComparator orderByComparator) throws SystemException {
4168 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4169 return findByG_V(groupId, vocabularyIds, start, end,
4170 orderByComparator);
4171 }
4172
4173 StringBundler query = new StringBundler();
4174
4175 if (getDB().isSupportsInlineDistinct()) {
4176 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
4177 }
4178 else {
4179 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4180 }
4181
4182 boolean conjunctionable = false;
4183
4184 if (conjunctionable) {
4185 query.append(WHERE_AND);
4186 }
4187
4188 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4189
4190 conjunctionable = true;
4191
4192 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4193 if (conjunctionable) {
4194 query.append(WHERE_AND);
4195 }
4196
4197 query.append(StringPool.OPEN_PARENTHESIS);
4198
4199 for (int i = 0; i < vocabularyIds.length; i++) {
4200 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4201
4202 if ((i + 1) < vocabularyIds.length) {
4203 query.append(WHERE_OR);
4204 }
4205 }
4206
4207 query.append(StringPool.CLOSE_PARENTHESIS);
4208
4209 conjunctionable = true;
4210 }
4211
4212 if (!getDB().isSupportsInlineDistinct()) {
4213 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4214 }
4215
4216 if (orderByComparator != null) {
4217 if (getDB().isSupportsInlineDistinct()) {
4218 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4219 orderByComparator, true);
4220 }
4221 else {
4222 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4223 orderByComparator, true);
4224 }
4225 }
4226 else {
4227 if (getDB().isSupportsInlineDistinct()) {
4228 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4229 }
4230 else {
4231 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
4232 }
4233 }
4234
4235 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4236 AssetCategory.class.getName(),
4237 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4238
4239 Session session = null;
4240
4241 try {
4242 session = openSession();
4243
4244 SQLQuery q = session.createSQLQuery(sql);
4245
4246 if (getDB().isSupportsInlineDistinct()) {
4247 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
4248 }
4249 else {
4250 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
4251 }
4252
4253 QueryPos qPos = QueryPos.getInstance(q);
4254
4255 qPos.add(groupId);
4256
4257 if (vocabularyIds != null) {
4258 qPos.add(vocabularyIds);
4259 }
4260
4261 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
4262 end);
4263 }
4264 catch (Exception e) {
4265 throw processException(e);
4266 }
4267 finally {
4268 closeSession(session);
4269 }
4270 }
4271
4272
4284 @Override
4285 public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds)
4286 throws SystemException {
4287 return findByG_V(groupId, vocabularyIds, QueryUtil.ALL_POS,
4288 QueryUtil.ALL_POS, null);
4289 }
4290
4291
4305 @Override
4306 public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4307 int start, int end) throws SystemException {
4308 return findByG_V(groupId, vocabularyIds, start, end, null);
4309 }
4310
4311
4326 @Override
4327 public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4328 int start, int end, OrderByComparator orderByComparator)
4329 throws SystemException {
4330 if ((vocabularyIds != null) && (vocabularyIds.length == 1)) {
4331 return findByG_V(groupId, vocabularyIds[0], start, end,
4332 orderByComparator);
4333 }
4334
4335 boolean pagination = true;
4336 Object[] finderArgs = null;
4337
4338 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4339 (orderByComparator == null)) {
4340 pagination = false;
4341 finderArgs = new Object[] { groupId, StringUtil.merge(vocabularyIds) };
4342 }
4343 else {
4344 finderArgs = new Object[] {
4345 groupId, StringUtil.merge(vocabularyIds),
4346
4347 start, end, orderByComparator
4348 };
4349 }
4350
4351 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4352 finderArgs, this);
4353
4354 if ((list != null) && !list.isEmpty()) {
4355 for (AssetCategory assetCategory : list) {
4356 if ((groupId != assetCategory.getGroupId()) ||
4357 !ArrayUtil.contains(vocabularyIds,
4358 assetCategory.getVocabularyId())) {
4359 list = null;
4360
4361 break;
4362 }
4363 }
4364 }
4365
4366 if (list == null) {
4367 StringBundler query = new StringBundler();
4368
4369 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4370
4371 boolean conjunctionable = false;
4372
4373 if (conjunctionable) {
4374 query.append(WHERE_AND);
4375 }
4376
4377 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4378
4379 conjunctionable = true;
4380
4381 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4382 if (conjunctionable) {
4383 query.append(WHERE_AND);
4384 }
4385
4386 query.append(StringPool.OPEN_PARENTHESIS);
4387
4388 for (int i = 0; i < vocabularyIds.length; i++) {
4389 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4390
4391 if ((i + 1) < vocabularyIds.length) {
4392 query.append(WHERE_OR);
4393 }
4394 }
4395
4396 query.append(StringPool.CLOSE_PARENTHESIS);
4397
4398 conjunctionable = true;
4399 }
4400
4401 if (orderByComparator != null) {
4402 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4403 orderByComparator);
4404 }
4405 else
4406 if (pagination) {
4407 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4408 }
4409
4410 String sql = query.toString();
4411
4412 Session session = null;
4413
4414 try {
4415 session = openSession();
4416
4417 Query q = session.createQuery(sql);
4418
4419 QueryPos qPos = QueryPos.getInstance(q);
4420
4421 qPos.add(groupId);
4422
4423 if (vocabularyIds != null) {
4424 qPos.add(vocabularyIds);
4425 }
4426
4427 if (!pagination) {
4428 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4429 start, end, false);
4430
4431 Collections.sort(list);
4432
4433 list = new UnmodifiableList<AssetCategory>(list);
4434 }
4435 else {
4436 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4437 start, end);
4438 }
4439
4440 cacheResult(list);
4441
4442 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4443 finderArgs, list);
4444 }
4445 catch (Exception e) {
4446 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4447 finderArgs);
4448
4449 throw processException(e);
4450 }
4451 finally {
4452 closeSession(session);
4453 }
4454 }
4455
4456 return list;
4457 }
4458
4459
4466 @Override
4467 public void removeByG_V(long groupId, long vocabularyId)
4468 throws SystemException {
4469 for (AssetCategory assetCategory : findByG_V(groupId, vocabularyId,
4470 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4471 remove(assetCategory);
4472 }
4473 }
4474
4475
4483 @Override
4484 public int countByG_V(long groupId, long vocabularyId)
4485 throws SystemException {
4486 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_V;
4487
4488 Object[] finderArgs = new Object[] { groupId, vocabularyId };
4489
4490 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4491 this);
4492
4493 if (count == null) {
4494 StringBundler query = new StringBundler(3);
4495
4496 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4497
4498 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4499
4500 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4501
4502 String sql = query.toString();
4503
4504 Session session = null;
4505
4506 try {
4507 session = openSession();
4508
4509 Query q = session.createQuery(sql);
4510
4511 QueryPos qPos = QueryPos.getInstance(q);
4512
4513 qPos.add(groupId);
4514
4515 qPos.add(vocabularyId);
4516
4517 count = (Long)q.uniqueResult();
4518
4519 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4520 }
4521 catch (Exception e) {
4522 FinderCacheUtil.removeResult(finderPath, finderArgs);
4523
4524 throw processException(e);
4525 }
4526 finally {
4527 closeSession(session);
4528 }
4529 }
4530
4531 return count.intValue();
4532 }
4533
4534
4542 @Override
4543 public int countByG_V(long groupId, long[] vocabularyIds)
4544 throws SystemException {
4545 Object[] finderArgs = new Object[] {
4546 groupId, StringUtil.merge(vocabularyIds)
4547 };
4548
4549 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4550 finderArgs, this);
4551
4552 if (count == null) {
4553 StringBundler query = new StringBundler();
4554
4555 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4556
4557 boolean conjunctionable = false;
4558
4559 if (conjunctionable) {
4560 query.append(WHERE_AND);
4561 }
4562
4563 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4564
4565 conjunctionable = true;
4566
4567 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4568 if (conjunctionable) {
4569 query.append(WHERE_AND);
4570 }
4571
4572 query.append(StringPool.OPEN_PARENTHESIS);
4573
4574 for (int i = 0; i < vocabularyIds.length; i++) {
4575 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4576
4577 if ((i + 1) < vocabularyIds.length) {
4578 query.append(WHERE_OR);
4579 }
4580 }
4581
4582 query.append(StringPool.CLOSE_PARENTHESIS);
4583
4584 conjunctionable = true;
4585 }
4586
4587 String sql = query.toString();
4588
4589 Session session = null;
4590
4591 try {
4592 session = openSession();
4593
4594 Query q = session.createQuery(sql);
4595
4596 QueryPos qPos = QueryPos.getInstance(q);
4597
4598 qPos.add(groupId);
4599
4600 if (vocabularyIds != null) {
4601 qPos.add(vocabularyIds);
4602 }
4603
4604 count = (Long)q.uniqueResult();
4605
4606 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4607 finderArgs, count);
4608 }
4609 catch (Exception e) {
4610 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4611 finderArgs);
4612
4613 throw processException(e);
4614 }
4615 finally {
4616 closeSession(session);
4617 }
4618 }
4619
4620 return count.intValue();
4621 }
4622
4623
4631 @Override
4632 public int filterCountByG_V(long groupId, long vocabularyId)
4633 throws SystemException {
4634 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4635 return countByG_V(groupId, vocabularyId);
4636 }
4637
4638 StringBundler query = new StringBundler(3);
4639
4640 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4641
4642 query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4643
4644 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4645
4646 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4647 AssetCategory.class.getName(),
4648 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4649
4650 Session session = null;
4651
4652 try {
4653 session = openSession();
4654
4655 SQLQuery q = session.createSQLQuery(sql);
4656
4657 q.addScalar(COUNT_COLUMN_NAME,
4658 com.liferay.portal.kernel.dao.orm.Type.LONG);
4659
4660 QueryPos qPos = QueryPos.getInstance(q);
4661
4662 qPos.add(groupId);
4663
4664 qPos.add(vocabularyId);
4665
4666 Long count = (Long)q.uniqueResult();
4667
4668 return count.intValue();
4669 }
4670 catch (Exception e) {
4671 throw processException(e);
4672 }
4673 finally {
4674 closeSession(session);
4675 }
4676 }
4677
4678
4686 @Override
4687 public int filterCountByG_V(long groupId, long[] vocabularyIds)
4688 throws SystemException {
4689 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4690 return countByG_V(groupId, vocabularyIds);
4691 }
4692
4693 StringBundler query = new StringBundler();
4694
4695 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4696
4697 boolean conjunctionable = false;
4698
4699 if (conjunctionable) {
4700 query.append(WHERE_AND);
4701 }
4702
4703 query.append(_FINDER_COLUMN_G_V_GROUPID_5);
4704
4705 conjunctionable = true;
4706
4707 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
4708 if (conjunctionable) {
4709 query.append(WHERE_AND);
4710 }
4711
4712 query.append(StringPool.OPEN_PARENTHESIS);
4713
4714 for (int i = 0; i < vocabularyIds.length; i++) {
4715 query.append(_FINDER_COLUMN_G_V_VOCABULARYID_5);
4716
4717 if ((i + 1) < vocabularyIds.length) {
4718 query.append(WHERE_OR);
4719 }
4720 }
4721
4722 query.append(StringPool.CLOSE_PARENTHESIS);
4723
4724 conjunctionable = true;
4725 }
4726
4727 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4728 AssetCategory.class.getName(),
4729 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4730
4731 Session session = null;
4732
4733 try {
4734 session = openSession();
4735
4736 SQLQuery q = session.createSQLQuery(sql);
4737
4738 q.addScalar(COUNT_COLUMN_NAME,
4739 com.liferay.portal.kernel.dao.orm.Type.LONG);
4740
4741 QueryPos qPos = QueryPos.getInstance(q);
4742
4743 qPos.add(groupId);
4744
4745 if (vocabularyIds != null) {
4746 qPos.add(vocabularyIds);
4747 }
4748
4749 Long count = (Long)q.uniqueResult();
4750
4751 return count.intValue();
4752 }
4753 catch (Exception e) {
4754 throw processException(e);
4755 }
4756 finally {
4757 closeSession(session);
4758 }
4759 }
4760
4761 private static final String _FINDER_COLUMN_G_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
4762 private static final String _FINDER_COLUMN_G_V_GROUPID_5 = "(" +
4763 removeConjunction(_FINDER_COLUMN_G_V_GROUPID_2) + ")";
4764 private static final String _FINDER_COLUMN_G_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
4765 private static final String _FINDER_COLUMN_G_V_VOCABULARYID_5 = "(" +
4766 removeConjunction(_FINDER_COLUMN_G_V_VOCABULARYID_2) + ")";
4767 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4768 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4769 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4770 "findByP_N",
4771 new String[] {
4772 Long.class.getName(), String.class.getName(),
4773
4774 Integer.class.getName(), Integer.class.getName(),
4775 OrderByComparator.class.getName()
4776 });
4777 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4778 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4779 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4780 "findByP_N",
4781 new String[] { Long.class.getName(), String.class.getName() },
4782 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4783 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
4784 public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4785 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4786 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
4787 new String[] { Long.class.getName(), String.class.getName() });
4788
4789
4797 @Override
4798 public List<AssetCategory> findByP_N(long parentCategoryId, String name)
4799 throws SystemException {
4800 return findByP_N(parentCategoryId, name, QueryUtil.ALL_POS,
4801 QueryUtil.ALL_POS, null);
4802 }
4803
4804
4818 @Override
4819 public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4820 int start, int end) throws SystemException {
4821 return findByP_N(parentCategoryId, name, start, end, null);
4822 }
4823
4824
4839 @Override
4840 public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4841 int start, int end, OrderByComparator orderByComparator)
4842 throws SystemException {
4843 boolean pagination = true;
4844 FinderPath finderPath = null;
4845 Object[] finderArgs = null;
4846
4847 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4848 (orderByComparator == null)) {
4849 pagination = false;
4850 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
4851 finderArgs = new Object[] { parentCategoryId, name };
4852 }
4853 else {
4854 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
4855 finderArgs = new Object[] {
4856 parentCategoryId, name,
4857
4858 start, end, orderByComparator
4859 };
4860 }
4861
4862 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
4863 finderArgs, this);
4864
4865 if ((list != null) && !list.isEmpty()) {
4866 for (AssetCategory assetCategory : list) {
4867 if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
4868 !Validator.equals(name, assetCategory.getName())) {
4869 list = null;
4870
4871 break;
4872 }
4873 }
4874 }
4875
4876 if (list == null) {
4877 StringBundler query = null;
4878
4879 if (orderByComparator != null) {
4880 query = new StringBundler(4 +
4881 (orderByComparator.getOrderByFields().length * 3));
4882 }
4883 else {
4884 query = new StringBundler(4);
4885 }
4886
4887 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4888
4889 query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4890
4891 boolean bindName = false;
4892
4893 if (name == null) {
4894 query.append(_FINDER_COLUMN_P_N_NAME_1);
4895 }
4896 else if (name.equals(StringPool.BLANK)) {
4897 query.append(_FINDER_COLUMN_P_N_NAME_3);
4898 }
4899 else {
4900 bindName = true;
4901
4902 query.append(_FINDER_COLUMN_P_N_NAME_2);
4903 }
4904
4905 if (orderByComparator != null) {
4906 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4907 orderByComparator);
4908 }
4909 else
4910 if (pagination) {
4911 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4912 }
4913
4914 String sql = query.toString();
4915
4916 Session session = null;
4917
4918 try {
4919 session = openSession();
4920
4921 Query q = session.createQuery(sql);
4922
4923 QueryPos qPos = QueryPos.getInstance(q);
4924
4925 qPos.add(parentCategoryId);
4926
4927 if (bindName) {
4928 qPos.add(name);
4929 }
4930
4931 if (!pagination) {
4932 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4933 start, end, false);
4934
4935 Collections.sort(list);
4936
4937 list = new UnmodifiableList<AssetCategory>(list);
4938 }
4939 else {
4940 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4941 start, end);
4942 }
4943
4944 cacheResult(list);
4945
4946 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4947 }
4948 catch (Exception e) {
4949 FinderCacheUtil.removeResult(finderPath, finderArgs);
4950
4951 throw processException(e);
4952 }
4953 finally {
4954 closeSession(session);
4955 }
4956 }
4957
4958 return list;
4959 }
4960
4961
4971 @Override
4972 public AssetCategory findByP_N_First(long parentCategoryId, String name,
4973 OrderByComparator orderByComparator)
4974 throws NoSuchCategoryException, SystemException {
4975 AssetCategory assetCategory = fetchByP_N_First(parentCategoryId, name,
4976 orderByComparator);
4977
4978 if (assetCategory != null) {
4979 return assetCategory;
4980 }
4981
4982 StringBundler msg = new StringBundler(6);
4983
4984 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4985
4986 msg.append("parentCategoryId=");
4987 msg.append(parentCategoryId);
4988
4989 msg.append(", name=");
4990 msg.append(name);
4991
4992 msg.append(StringPool.CLOSE_CURLY_BRACE);
4993
4994 throw new NoSuchCategoryException(msg.toString());
4995 }
4996
4997
5006 @Override
5007 public AssetCategory fetchByP_N_First(long parentCategoryId, String name,
5008 OrderByComparator orderByComparator) throws SystemException {
5009 List<AssetCategory> list = findByP_N(parentCategoryId, name, 0, 1,
5010 orderByComparator);
5011
5012 if (!list.isEmpty()) {
5013 return list.get(0);
5014 }
5015
5016 return null;
5017 }
5018
5019
5029 @Override
5030 public AssetCategory findByP_N_Last(long parentCategoryId, String name,
5031 OrderByComparator orderByComparator)
5032 throws NoSuchCategoryException, SystemException {
5033 AssetCategory assetCategory = fetchByP_N_Last(parentCategoryId, name,
5034 orderByComparator);
5035
5036 if (assetCategory != null) {
5037 return assetCategory;
5038 }
5039
5040 StringBundler msg = new StringBundler(6);
5041
5042 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5043
5044 msg.append("parentCategoryId=");
5045 msg.append(parentCategoryId);
5046
5047 msg.append(", name=");
5048 msg.append(name);
5049
5050 msg.append(StringPool.CLOSE_CURLY_BRACE);
5051
5052 throw new NoSuchCategoryException(msg.toString());
5053 }
5054
5055
5064 @Override
5065 public AssetCategory fetchByP_N_Last(long parentCategoryId, String name,
5066 OrderByComparator orderByComparator) throws SystemException {
5067 int count = countByP_N(parentCategoryId, name);
5068
5069 if (count == 0) {
5070 return null;
5071 }
5072
5073 List<AssetCategory> list = findByP_N(parentCategoryId, name, count - 1,
5074 count, orderByComparator);
5075
5076 if (!list.isEmpty()) {
5077 return list.get(0);
5078 }
5079
5080 return null;
5081 }
5082
5083
5094 @Override
5095 public AssetCategory[] findByP_N_PrevAndNext(long categoryId,
5096 long parentCategoryId, String name, OrderByComparator orderByComparator)
5097 throws NoSuchCategoryException, SystemException {
5098 AssetCategory assetCategory = findByPrimaryKey(categoryId);
5099
5100 Session session = null;
5101
5102 try {
5103 session = openSession();
5104
5105 AssetCategory[] array = new AssetCategoryImpl[3];
5106
5107 array[0] = getByP_N_PrevAndNext(session, assetCategory,
5108 parentCategoryId, name, orderByComparator, true);
5109
5110 array[1] = assetCategory;
5111
5112 array[2] = getByP_N_PrevAndNext(session, assetCategory,
5113 parentCategoryId, name, orderByComparator, false);
5114
5115 return array;
5116 }
5117 catch (Exception e) {
5118 throw processException(e);
5119 }
5120 finally {
5121 closeSession(session);
5122 }
5123 }
5124
5125 protected AssetCategory getByP_N_PrevAndNext(Session session,
5126 AssetCategory assetCategory, long parentCategoryId, String name,
5127 OrderByComparator orderByComparator, boolean previous) {
5128 StringBundler query = null;
5129
5130 if (orderByComparator != null) {
5131 query = new StringBundler(6 +
5132 (orderByComparator.getOrderByFields().length * 6));
5133 }
5134 else {
5135 query = new StringBundler(3);
5136 }
5137
5138 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5139
5140 query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
5141
5142 boolean bindName = false;
5143
5144 if (name == null) {
5145 query.append(_FINDER_COLUMN_P_N_NAME_1);
5146 }
5147 else if (name.equals(StringPool.BLANK)) {
5148 query.append(_FINDER_COLUMN_P_N_NAME_3);
5149 }
5150 else {
5151 bindName = true;
5152
5153 query.append(_FINDER_COLUMN_P_N_NAME_2);
5154 }
5155
5156 if (orderByComparator != null) {
5157 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5158
5159 if (orderByConditionFields.length > 0) {
5160 query.append(WHERE_AND);
5161 }
5162
5163 for (int i = 0; i < orderByConditionFields.length; i++) {
5164 query.append(_ORDER_BY_ENTITY_ALIAS);
5165 query.append(orderByConditionFields[i]);
5166
5167 if ((i + 1) < orderByConditionFields.length) {
5168 if (orderByComparator.isAscending() ^ previous) {
5169 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5170 }
5171 else {
5172 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5173 }
5174 }
5175 else {
5176 if (orderByComparator.isAscending() ^ previous) {
5177 query.append(WHERE_GREATER_THAN);
5178 }
5179 else {
5180 query.append(WHERE_LESSER_THAN);
5181 }
5182 }
5183 }
5184
5185 query.append(ORDER_BY_CLAUSE);
5186
5187 String[] orderByFields = orderByComparator.getOrderByFields();
5188
5189 for (int i = 0; i < orderByFields.length; i++) {
5190 query.append(_ORDER_BY_ENTITY_ALIAS);
5191 query.append(orderByFields[i]);
5192
5193 if ((i + 1) < orderByFields.length) {
5194 if (orderByComparator.isAscending() ^ previous) {
5195 query.append(ORDER_BY_ASC_HAS_NEXT);
5196 }
5197 else {
5198 query.append(ORDER_BY_DESC_HAS_NEXT);
5199 }
5200 }
5201 else {
5202 if (orderByComparator.isAscending() ^ previous) {
5203 query.append(ORDER_BY_ASC);
5204 }
5205 else {
5206 query.append(ORDER_BY_DESC);
5207 }
5208 }
5209 }
5210 }
5211 else {
5212 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5213 }
5214
5215 String sql = query.toString();
5216
5217 Query q = session.createQuery(sql);
5218
5219 q.setFirstResult(0);
5220 q.setMaxResults(2);
5221
5222 QueryPos qPos = QueryPos.getInstance(q);
5223
5224 qPos.add(parentCategoryId);
5225
5226 if (bindName) {
5227 qPos.add(name);
5228 }
5229
5230 if (orderByComparator != null) {
5231 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5232
5233 for (Object value : values) {
5234 qPos.add(value);
5235 }
5236 }
5237
5238 List<AssetCategory> list = q.list();
5239
5240 if (list.size() == 2) {
5241 return list.get(1);
5242 }
5243 else {
5244 return null;
5245 }
5246 }
5247
5248
5255 @Override
5256 public void removeByP_N(long parentCategoryId, String name)
5257 throws SystemException {
5258 for (AssetCategory assetCategory : findByP_N(parentCategoryId, name,
5259 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5260 remove(assetCategory);
5261 }
5262 }
5263
5264
5272 @Override
5273 public int countByP_N(long parentCategoryId, String name)
5274 throws SystemException {
5275 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
5276
5277 Object[] finderArgs = new Object[] { parentCategoryId, name };
5278
5279 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5280 this);
5281
5282 if (count == null) {
5283 StringBundler query = new StringBundler(3);
5284
5285 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5286
5287 query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
5288
5289 boolean bindName = false;
5290
5291 if (name == null) {
5292 query.append(_FINDER_COLUMN_P_N_NAME_1);
5293 }
5294 else if (name.equals(StringPool.BLANK)) {
5295 query.append(_FINDER_COLUMN_P_N_NAME_3);
5296 }
5297 else {
5298 bindName = true;
5299
5300 query.append(_FINDER_COLUMN_P_N_NAME_2);
5301 }
5302
5303 String sql = query.toString();
5304
5305 Session session = null;
5306
5307 try {
5308 session = openSession();
5309
5310 Query q = session.createQuery(sql);
5311
5312 QueryPos qPos = QueryPos.getInstance(q);
5313
5314 qPos.add(parentCategoryId);
5315
5316 if (bindName) {
5317 qPos.add(name);
5318 }
5319
5320 count = (Long)q.uniqueResult();
5321
5322 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5323 }
5324 catch (Exception e) {
5325 FinderCacheUtil.removeResult(finderPath, finderArgs);
5326
5327 throw processException(e);
5328 }
5329 finally {
5330 closeSession(session);
5331 }
5332 }
5333
5334 return count.intValue();
5335 }
5336
5337 private static final String _FINDER_COLUMN_P_N_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5338 private static final String _FINDER_COLUMN_P_N_NAME_1 = "assetCategory.name IS NULL";
5339 private static final String _FINDER_COLUMN_P_N_NAME_2 = "assetCategory.name = ?";
5340 private static final String _FINDER_COLUMN_P_N_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '')";
5341 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5342 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5343 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5344 "findByP_V",
5345 new String[] {
5346 Long.class.getName(), Long.class.getName(),
5347
5348 Integer.class.getName(), Integer.class.getName(),
5349 OrderByComparator.class.getName()
5350 });
5351 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5352 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5353 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5354 "findByP_V",
5355 new String[] { Long.class.getName(), Long.class.getName() },
5356 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5357 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
5358 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
5359 public static final FinderPath FINDER_PATH_COUNT_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5360 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5361 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_V",
5362 new String[] { Long.class.getName(), Long.class.getName() });
5363
5364
5372 @Override
5373 public List<AssetCategory> findByP_V(long parentCategoryId,
5374 long vocabularyId) throws SystemException {
5375 return findByP_V(parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
5376 QueryUtil.ALL_POS, null);
5377 }
5378
5379
5393 @Override
5394 public List<AssetCategory> findByP_V(long parentCategoryId,
5395 long vocabularyId, int start, int end) throws SystemException {
5396 return findByP_V(parentCategoryId, vocabularyId, start, end, null);
5397 }
5398
5399
5414 @Override
5415 public List<AssetCategory> findByP_V(long parentCategoryId,
5416 long vocabularyId, int start, int end,
5417 OrderByComparator orderByComparator) throws SystemException {
5418 boolean pagination = true;
5419 FinderPath finderPath = null;
5420 Object[] finderArgs = null;
5421
5422 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5423 (orderByComparator == null)) {
5424 pagination = false;
5425 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V;
5426 finderArgs = new Object[] { parentCategoryId, vocabularyId };
5427 }
5428 else {
5429 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V;
5430 finderArgs = new Object[] {
5431 parentCategoryId, vocabularyId,
5432
5433 start, end, orderByComparator
5434 };
5435 }
5436
5437 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
5438 finderArgs, this);
5439
5440 if ((list != null) && !list.isEmpty()) {
5441 for (AssetCategory assetCategory : list) {
5442 if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
5443 (vocabularyId != assetCategory.getVocabularyId())) {
5444 list = null;
5445
5446 break;
5447 }
5448 }
5449 }
5450
5451 if (list == null) {
5452 StringBundler query = null;
5453
5454 if (orderByComparator != null) {
5455 query = new StringBundler(4 +
5456 (orderByComparator.getOrderByFields().length * 3));
5457 }
5458 else {
5459 query = new StringBundler(4);
5460 }
5461
5462 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5463
5464 query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5465
5466 query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5467
5468 if (orderByComparator != null) {
5469 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5470 orderByComparator);
5471 }
5472 else
5473 if (pagination) {
5474 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5475 }
5476
5477 String sql = query.toString();
5478
5479 Session session = null;
5480
5481 try {
5482 session = openSession();
5483
5484 Query q = session.createQuery(sql);
5485
5486 QueryPos qPos = QueryPos.getInstance(q);
5487
5488 qPos.add(parentCategoryId);
5489
5490 qPos.add(vocabularyId);
5491
5492 if (!pagination) {
5493 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5494 start, end, false);
5495
5496 Collections.sort(list);
5497
5498 list = new UnmodifiableList<AssetCategory>(list);
5499 }
5500 else {
5501 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5502 start, end);
5503 }
5504
5505 cacheResult(list);
5506
5507 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5508 }
5509 catch (Exception e) {
5510 FinderCacheUtil.removeResult(finderPath, finderArgs);
5511
5512 throw processException(e);
5513 }
5514 finally {
5515 closeSession(session);
5516 }
5517 }
5518
5519 return list;
5520 }
5521
5522
5532 @Override
5533 public AssetCategory findByP_V_First(long parentCategoryId,
5534 long vocabularyId, OrderByComparator orderByComparator)
5535 throws NoSuchCategoryException, SystemException {
5536 AssetCategory assetCategory = fetchByP_V_First(parentCategoryId,
5537 vocabularyId, orderByComparator);
5538
5539 if (assetCategory != null) {
5540 return assetCategory;
5541 }
5542
5543 StringBundler msg = new StringBundler(6);
5544
5545 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5546
5547 msg.append("parentCategoryId=");
5548 msg.append(parentCategoryId);
5549
5550 msg.append(", vocabularyId=");
5551 msg.append(vocabularyId);
5552
5553 msg.append(StringPool.CLOSE_CURLY_BRACE);
5554
5555 throw new NoSuchCategoryException(msg.toString());
5556 }
5557
5558
5567 @Override
5568 public AssetCategory fetchByP_V_First(long parentCategoryId,
5569 long vocabularyId, OrderByComparator orderByComparator)
5570 throws SystemException {
5571 List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId, 0,
5572 1, orderByComparator);
5573
5574 if (!list.isEmpty()) {
5575 return list.get(0);
5576 }
5577
5578 return null;
5579 }
5580
5581
5591 @Override
5592 public AssetCategory findByP_V_Last(long parentCategoryId,
5593 long vocabularyId, OrderByComparator orderByComparator)
5594 throws NoSuchCategoryException, SystemException {
5595 AssetCategory assetCategory = fetchByP_V_Last(parentCategoryId,
5596 vocabularyId, orderByComparator);
5597
5598 if (assetCategory != null) {
5599 return assetCategory;
5600 }
5601
5602 StringBundler msg = new StringBundler(6);
5603
5604 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5605
5606 msg.append("parentCategoryId=");
5607 msg.append(parentCategoryId);
5608
5609 msg.append(", vocabularyId=");
5610 msg.append(vocabularyId);
5611
5612 msg.append(StringPool.CLOSE_CURLY_BRACE);
5613
5614 throw new NoSuchCategoryException(msg.toString());
5615 }
5616
5617
5626 @Override
5627 public AssetCategory fetchByP_V_Last(long parentCategoryId,
5628 long vocabularyId, OrderByComparator orderByComparator)
5629 throws SystemException {
5630 int count = countByP_V(parentCategoryId, vocabularyId);
5631
5632 if (count == 0) {
5633 return null;
5634 }
5635
5636 List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId,
5637 count - 1, count, orderByComparator);
5638
5639 if (!list.isEmpty()) {
5640 return list.get(0);
5641 }
5642
5643 return null;
5644 }
5645
5646
5657 @Override
5658 public AssetCategory[] findByP_V_PrevAndNext(long categoryId,
5659 long parentCategoryId, long vocabularyId,
5660 OrderByComparator orderByComparator)
5661 throws NoSuchCategoryException, SystemException {
5662 AssetCategory assetCategory = findByPrimaryKey(categoryId);
5663
5664 Session session = null;
5665
5666 try {
5667 session = openSession();
5668
5669 AssetCategory[] array = new AssetCategoryImpl[3];
5670
5671 array[0] = getByP_V_PrevAndNext(session, assetCategory,
5672 parentCategoryId, vocabularyId, orderByComparator, true);
5673
5674 array[1] = assetCategory;
5675
5676 array[2] = getByP_V_PrevAndNext(session, assetCategory,
5677 parentCategoryId, vocabularyId, orderByComparator, false);
5678
5679 return array;
5680 }
5681 catch (Exception e) {
5682 throw processException(e);
5683 }
5684 finally {
5685 closeSession(session);
5686 }
5687 }
5688
5689 protected AssetCategory getByP_V_PrevAndNext(Session session,
5690 AssetCategory assetCategory, long parentCategoryId, long vocabularyId,
5691 OrderByComparator orderByComparator, boolean previous) {
5692 StringBundler query = null;
5693
5694 if (orderByComparator != null) {
5695 query = new StringBundler(6 +
5696 (orderByComparator.getOrderByFields().length * 6));
5697 }
5698 else {
5699 query = new StringBundler(3);
5700 }
5701
5702 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5703
5704 query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5705
5706 query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5707
5708 if (orderByComparator != null) {
5709 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5710
5711 if (orderByConditionFields.length > 0) {
5712 query.append(WHERE_AND);
5713 }
5714
5715 for (int i = 0; i < orderByConditionFields.length; i++) {
5716 query.append(_ORDER_BY_ENTITY_ALIAS);
5717 query.append(orderByConditionFields[i]);
5718
5719 if ((i + 1) < orderByConditionFields.length) {
5720 if (orderByComparator.isAscending() ^ previous) {
5721 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5722 }
5723 else {
5724 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5725 }
5726 }
5727 else {
5728 if (orderByComparator.isAscending() ^ previous) {
5729 query.append(WHERE_GREATER_THAN);
5730 }
5731 else {
5732 query.append(WHERE_LESSER_THAN);
5733 }
5734 }
5735 }
5736
5737 query.append(ORDER_BY_CLAUSE);
5738
5739 String[] orderByFields = orderByComparator.getOrderByFields();
5740
5741 for (int i = 0; i < orderByFields.length; i++) {
5742 query.append(_ORDER_BY_ENTITY_ALIAS);
5743 query.append(orderByFields[i]);
5744
5745 if ((i + 1) < orderByFields.length) {
5746 if (orderByComparator.isAscending() ^ previous) {
5747 query.append(ORDER_BY_ASC_HAS_NEXT);
5748 }
5749 else {
5750 query.append(ORDER_BY_DESC_HAS_NEXT);
5751 }
5752 }
5753 else {
5754 if (orderByComparator.isAscending() ^ previous) {
5755 query.append(ORDER_BY_ASC);
5756 }
5757 else {
5758 query.append(ORDER_BY_DESC);
5759 }
5760 }
5761 }
5762 }
5763 else {
5764 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5765 }
5766
5767 String sql = query.toString();
5768
5769 Query q = session.createQuery(sql);
5770
5771 q.setFirstResult(0);
5772 q.setMaxResults(2);
5773
5774 QueryPos qPos = QueryPos.getInstance(q);
5775
5776 qPos.add(parentCategoryId);
5777
5778 qPos.add(vocabularyId);
5779
5780 if (orderByComparator != null) {
5781 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5782
5783 for (Object value : values) {
5784 qPos.add(value);
5785 }
5786 }
5787
5788 List<AssetCategory> list = q.list();
5789
5790 if (list.size() == 2) {
5791 return list.get(1);
5792 }
5793 else {
5794 return null;
5795 }
5796 }
5797
5798
5805 @Override
5806 public void removeByP_V(long parentCategoryId, long vocabularyId)
5807 throws SystemException {
5808 for (AssetCategory assetCategory : findByP_V(parentCategoryId,
5809 vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5810 remove(assetCategory);
5811 }
5812 }
5813
5814
5822 @Override
5823 public int countByP_V(long parentCategoryId, long vocabularyId)
5824 throws SystemException {
5825 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_V;
5826
5827 Object[] finderArgs = new Object[] { parentCategoryId, vocabularyId };
5828
5829 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5830 this);
5831
5832 if (count == null) {
5833 StringBundler query = new StringBundler(3);
5834
5835 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5836
5837 query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5838
5839 query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5840
5841 String sql = query.toString();
5842
5843 Session session = null;
5844
5845 try {
5846 session = openSession();
5847
5848 Query q = session.createQuery(sql);
5849
5850 QueryPos qPos = QueryPos.getInstance(q);
5851
5852 qPos.add(parentCategoryId);
5853
5854 qPos.add(vocabularyId);
5855
5856 count = (Long)q.uniqueResult();
5857
5858 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5859 }
5860 catch (Exception e) {
5861 FinderCacheUtil.removeResult(finderPath, finderArgs);
5862
5863 throw processException(e);
5864 }
5865 finally {
5866 closeSession(session);
5867 }
5868 }
5869
5870 return count.intValue();
5871 }
5872
5873 private static final String _FINDER_COLUMN_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5874 private static final String _FINDER_COLUMN_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5875 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5876 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5877 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5878 "findByN_V",
5879 new String[] {
5880 String.class.getName(), Long.class.getName(),
5881
5882 Integer.class.getName(), Integer.class.getName(),
5883 OrderByComparator.class.getName()
5884 });
5885 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5886 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5887 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5888 "findByN_V",
5889 new String[] { String.class.getName(), Long.class.getName() },
5890 AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
5891 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
5892 public static final FinderPath FINDER_PATH_COUNT_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5893 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5894 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_V",
5895 new String[] { String.class.getName(), Long.class.getName() });
5896
5897
5905 @Override
5906 public List<AssetCategory> findByN_V(String name, long vocabularyId)
5907 throws SystemException {
5908 return findByN_V(name, vocabularyId, QueryUtil.ALL_POS,
5909 QueryUtil.ALL_POS, null);
5910 }
5911
5912
5926 @Override
5927 public List<AssetCategory> findByN_V(String name, long vocabularyId,
5928 int start, int end) throws SystemException {
5929 return findByN_V(name, vocabularyId, start, end, null);
5930 }
5931
5932
5947 @Override
5948 public List<AssetCategory> findByN_V(String name, long vocabularyId,
5949 int start, int end, OrderByComparator orderByComparator)
5950 throws SystemException {
5951 boolean pagination = true;
5952 FinderPath finderPath = null;
5953 Object[] finderArgs = null;
5954
5955 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5956 (orderByComparator == null)) {
5957 pagination = false;
5958 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V;
5959 finderArgs = new Object[] { name, vocabularyId };
5960 }
5961 else {
5962 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V;
5963 finderArgs = new Object[] {
5964 name, vocabularyId,
5965
5966 start, end, orderByComparator
5967 };
5968 }
5969
5970 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
5971 finderArgs, this);
5972
5973 if ((list != null) && !list.isEmpty()) {
5974 for (AssetCategory assetCategory : list) {
5975 if (!Validator.equals(name, assetCategory.getName()) ||
5976 (vocabularyId != assetCategory.getVocabularyId())) {
5977 list = null;
5978
5979 break;
5980 }
5981 }
5982 }
5983
5984 if (list == null) {
5985 StringBundler query = null;
5986
5987 if (orderByComparator != null) {
5988 query = new StringBundler(4 +
5989 (orderByComparator.getOrderByFields().length * 3));
5990 }
5991 else {
5992 query = new StringBundler(4);
5993 }
5994
5995 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5996
5997 boolean bindName = false;
5998
5999 if (name == null) {
6000 query.append(_FINDER_COLUMN_N_V_NAME_1);
6001 }
6002 else if (name.equals(StringPool.BLANK)) {
6003 query.append(_FINDER_COLUMN_N_V_NAME_3);
6004 }
6005 else {
6006 bindName = true;
6007
6008 query.append(_FINDER_COLUMN_N_V_NAME_2);
6009 }
6010
6011 query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6012
6013 if (orderByComparator != null) {
6014 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6015 orderByComparator);
6016 }
6017 else
6018 if (pagination) {
6019 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6020 }
6021
6022 String sql = query.toString();
6023
6024 Session session = null;
6025
6026 try {
6027 session = openSession();
6028
6029 Query q = session.createQuery(sql);
6030
6031 QueryPos qPos = QueryPos.getInstance(q);
6032
6033 if (bindName) {
6034 qPos.add(name);
6035 }
6036
6037 qPos.add(vocabularyId);
6038
6039 if (!pagination) {
6040 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6041 start, end, false);
6042
6043 Collections.sort(list);
6044
6045 list = new UnmodifiableList<AssetCategory>(list);
6046 }
6047 else {
6048 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6049 start, end);
6050 }
6051
6052 cacheResult(list);
6053
6054 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6055 }
6056 catch (Exception e) {
6057 FinderCacheUtil.removeResult(finderPath, finderArgs);
6058
6059 throw processException(e);
6060 }
6061 finally {
6062 closeSession(session);
6063 }
6064 }
6065
6066 return list;
6067 }
6068
6069
6079 @Override
6080 public AssetCategory findByN_V_First(String name, long vocabularyId,
6081 OrderByComparator orderByComparator)
6082 throws NoSuchCategoryException, SystemException {
6083 AssetCategory assetCategory = fetchByN_V_First(name, vocabularyId,
6084 orderByComparator);
6085
6086 if (assetCategory != null) {
6087 return assetCategory;
6088 }
6089
6090 StringBundler msg = new StringBundler(6);
6091
6092 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6093
6094 msg.append("name=");
6095 msg.append(name);
6096
6097 msg.append(", vocabularyId=");
6098 msg.append(vocabularyId);
6099
6100 msg.append(StringPool.CLOSE_CURLY_BRACE);
6101
6102 throw new NoSuchCategoryException(msg.toString());
6103 }
6104
6105
6114 @Override
6115 public AssetCategory fetchByN_V_First(String name, long vocabularyId,
6116 OrderByComparator orderByComparator) throws SystemException {
6117 List<AssetCategory> list = findByN_V(name, vocabularyId, 0, 1,
6118 orderByComparator);
6119
6120 if (!list.isEmpty()) {
6121 return list.get(0);
6122 }
6123
6124 return null;
6125 }
6126
6127
6137 @Override
6138 public AssetCategory findByN_V_Last(String name, long vocabularyId,
6139 OrderByComparator orderByComparator)
6140 throws NoSuchCategoryException, SystemException {
6141 AssetCategory assetCategory = fetchByN_V_Last(name, vocabularyId,
6142 orderByComparator);
6143
6144 if (assetCategory != null) {
6145 return assetCategory;
6146 }
6147
6148 StringBundler msg = new StringBundler(6);
6149
6150 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6151
6152 msg.append("name=");
6153 msg.append(name);
6154
6155 msg.append(", vocabularyId=");
6156 msg.append(vocabularyId);
6157
6158 msg.append(StringPool.CLOSE_CURLY_BRACE);
6159
6160 throw new NoSuchCategoryException(msg.toString());
6161 }
6162
6163
6172 @Override
6173 public AssetCategory fetchByN_V_Last(String name, long vocabularyId,
6174 OrderByComparator orderByComparator) throws SystemException {
6175 int count = countByN_V(name, vocabularyId);
6176
6177 if (count == 0) {
6178 return null;
6179 }
6180
6181 List<AssetCategory> list = findByN_V(name, vocabularyId, count - 1,
6182 count, orderByComparator);
6183
6184 if (!list.isEmpty()) {
6185 return list.get(0);
6186 }
6187
6188 return null;
6189 }
6190
6191
6202 @Override
6203 public AssetCategory[] findByN_V_PrevAndNext(long categoryId, String name,
6204 long vocabularyId, OrderByComparator orderByComparator)
6205 throws NoSuchCategoryException, SystemException {
6206 AssetCategory assetCategory = findByPrimaryKey(categoryId);
6207
6208 Session session = null;
6209
6210 try {
6211 session = openSession();
6212
6213 AssetCategory[] array = new AssetCategoryImpl[3];
6214
6215 array[0] = getByN_V_PrevAndNext(session, assetCategory, name,
6216 vocabularyId, orderByComparator, true);
6217
6218 array[1] = assetCategory;
6219
6220 array[2] = getByN_V_PrevAndNext(session, assetCategory, name,
6221 vocabularyId, orderByComparator, false);
6222
6223 return array;
6224 }
6225 catch (Exception e) {
6226 throw processException(e);
6227 }
6228 finally {
6229 closeSession(session);
6230 }
6231 }
6232
6233 protected AssetCategory getByN_V_PrevAndNext(Session session,
6234 AssetCategory assetCategory, String name, long vocabularyId,
6235 OrderByComparator orderByComparator, boolean previous) {
6236 StringBundler query = null;
6237
6238 if (orderByComparator != null) {
6239 query = new StringBundler(6 +
6240 (orderByComparator.getOrderByFields().length * 6));
6241 }
6242 else {
6243 query = new StringBundler(3);
6244 }
6245
6246 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6247
6248 boolean bindName = false;
6249
6250 if (name == null) {
6251 query.append(_FINDER_COLUMN_N_V_NAME_1);
6252 }
6253 else if (name.equals(StringPool.BLANK)) {
6254 query.append(_FINDER_COLUMN_N_V_NAME_3);
6255 }
6256 else {
6257 bindName = true;
6258
6259 query.append(_FINDER_COLUMN_N_V_NAME_2);
6260 }
6261
6262 query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6263
6264 if (orderByComparator != null) {
6265 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6266
6267 if (orderByConditionFields.length > 0) {
6268 query.append(WHERE_AND);
6269 }
6270
6271 for (int i = 0; i < orderByConditionFields.length; i++) {
6272 query.append(_ORDER_BY_ENTITY_ALIAS);
6273 query.append(orderByConditionFields[i]);
6274
6275 if ((i + 1) < orderByConditionFields.length) {
6276 if (orderByComparator.isAscending() ^ previous) {
6277 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6278 }
6279 else {
6280 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6281 }
6282 }
6283 else {
6284 if (orderByComparator.isAscending() ^ previous) {
6285 query.append(WHERE_GREATER_THAN);
6286 }
6287 else {
6288 query.append(WHERE_LESSER_THAN);
6289 }
6290 }
6291 }
6292
6293 query.append(ORDER_BY_CLAUSE);
6294
6295 String[] orderByFields = orderByComparator.getOrderByFields();
6296
6297 for (int i = 0; i < orderByFields.length; i++) {
6298 query.append(_ORDER_BY_ENTITY_ALIAS);
6299 query.append(orderByFields[i]);
6300
6301 if ((i + 1) < orderByFields.length) {
6302 if (orderByComparator.isAscending() ^ previous) {
6303 query.append(ORDER_BY_ASC_HAS_NEXT);
6304 }
6305 else {
6306 query.append(ORDER_BY_DESC_HAS_NEXT);
6307 }
6308 }
6309 else {
6310 if (orderByComparator.isAscending() ^ previous) {
6311 query.append(ORDER_BY_ASC);
6312 }
6313 else {
6314 query.append(ORDER_BY_DESC);
6315 }
6316 }
6317 }
6318 }
6319 else {
6320 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6321 }
6322
6323 String sql = query.toString();
6324
6325 Query q = session.createQuery(sql);
6326
6327 q.setFirstResult(0);
6328 q.setMaxResults(2);
6329
6330 QueryPos qPos = QueryPos.getInstance(q);
6331
6332 if (bindName) {
6333 qPos.add(name);
6334 }
6335
6336 qPos.add(vocabularyId);
6337
6338 if (orderByComparator != null) {
6339 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6340
6341 for (Object value : values) {
6342 qPos.add(value);
6343 }
6344 }
6345
6346 List<AssetCategory> list = q.list();
6347
6348 if (list.size() == 2) {
6349 return list.get(1);
6350 }
6351 else {
6352 return null;
6353 }
6354 }
6355
6356
6363 @Override
6364 public void removeByN_V(String name, long vocabularyId)
6365 throws SystemException {
6366 for (AssetCategory assetCategory : findByN_V(name, vocabularyId,
6367 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6368 remove(assetCategory);
6369 }
6370 }
6371
6372
6380 @Override
6381 public int countByN_V(String name, long vocabularyId)
6382 throws SystemException {
6383 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_V;
6384
6385 Object[] finderArgs = new Object[] { name, vocabularyId };
6386
6387 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6388 this);
6389
6390 if (count == null) {
6391 StringBundler query = new StringBundler(3);
6392
6393 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
6394
6395 boolean bindName = false;
6396
6397 if (name == null) {
6398 query.append(_FINDER_COLUMN_N_V_NAME_1);
6399 }
6400 else if (name.equals(StringPool.BLANK)) {
6401 query.append(_FINDER_COLUMN_N_V_NAME_3);
6402 }
6403 else {
6404 bindName = true;
6405
6406 query.append(_FINDER_COLUMN_N_V_NAME_2);
6407 }
6408
6409 query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6410
6411 String sql = query.toString();
6412
6413 Session session = null;
6414
6415 try {
6416 session = openSession();
6417
6418 Query q = session.createQuery(sql);
6419
6420 QueryPos qPos = QueryPos.getInstance(q);
6421
6422 if (bindName) {
6423 qPos.add(name);
6424 }
6425
6426 qPos.add(vocabularyId);
6427
6428 count = (Long)q.uniqueResult();
6429
6430 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6431 }
6432 catch (Exception e) {
6433 FinderCacheUtil.removeResult(finderPath, finderArgs);
6434
6435 throw processException(e);
6436 }
6437 finally {
6438 closeSession(session);
6439 }
6440 }
6441
6442 return count.intValue();
6443 }
6444
6445 private static final String _FINDER_COLUMN_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
6446 private static final String _FINDER_COLUMN_N_V_NAME_2 = "assetCategory.name = ? AND ";
6447 private static final String _FINDER_COLUMN_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
6448 private static final String _FINDER_COLUMN_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
6449 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6450 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6451 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6452 "findByG_P_V",
6453 new String[] {
6454 Long.class.getName(), Long.class.getName(), Long.class.getName(),
6455
6456 Integer.class.getName(), Integer.class.getName(),
6457 OrderByComparator.class.getName()
6458 });
6459 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6460 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6461 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
6462 "findByG_P_V",
6463 new String[] {
6464 Long.class.getName(), Long.class.getName(), Long.class.getName()
6465 },
6466 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
6467 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
6468 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
6469 AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
6470 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6471 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6472 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_V",
6473 new String[] {
6474 Long.class.getName(), Long.class.getName(), Long.class.getName()
6475 });
6476
6477
6486 @Override
6487 public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6488 long vocabularyId) throws SystemException {
6489 return findByG_P_V(groupId, parentCategoryId, vocabularyId,
6490 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6491 }
6492
6493
6508 @Override
6509 public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6510 long vocabularyId, int start, int end) throws SystemException {
6511 return findByG_P_V(groupId, parentCategoryId, vocabularyId, start, end,
6512 null);
6513 }
6514
6515
6531 @Override
6532 public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6533 long vocabularyId, int start, int end,
6534 OrderByComparator orderByComparator) throws SystemException {
6535 boolean pagination = true;
6536 FinderPath finderPath = null;
6537 Object[] finderArgs = null;
6538
6539 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6540 (orderByComparator == null)) {
6541 pagination = false;
6542 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V;
6543 finderArgs = new Object[] { groupId, parentCategoryId, vocabularyId };
6544 }
6545 else {
6546 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_V;
6547 finderArgs = new Object[] {
6548 groupId, parentCategoryId, vocabularyId,
6549
6550 start, end, orderByComparator
6551 };
6552 }
6553
6554 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
6555 finderArgs, this);
6556
6557 if ((list != null) && !list.isEmpty()) {
6558 for (AssetCategory assetCategory : list) {
6559 if ((groupId != assetCategory.getGroupId()) ||
6560 (parentCategoryId != assetCategory.getParentCategoryId()) ||
6561 (vocabularyId != assetCategory.getVocabularyId())) {
6562 list = null;
6563
6564 break;
6565 }
6566 }
6567 }
6568
6569 if (list == null) {
6570 StringBundler query = null;
6571
6572 if (orderByComparator != null) {
6573 query = new StringBundler(5 +
6574 (orderByComparator.getOrderByFields().length * 3));
6575 }
6576 else {
6577 query = new StringBundler(5);
6578 }
6579
6580 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6581
6582 query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
6583
6584 query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
6585
6586 query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
6587
6588 if (orderByComparator != null) {
6589 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6590 orderByComparator);
6591 }
6592 else
6593 if (pagination) {
6594 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6595 }
6596
6597 String sql = query.toString();
6598
6599 Session session = null;
6600
6601 try {
6602 session = openSession();
6603
6604 Query q = session.createQuery(sql);
6605
6606 QueryPos qPos = QueryPos.getInstance(q);
6607
6608 qPos.add(groupId);
6609
6610 qPos.add(parentCategoryId);
6611
6612 qPos.add(vocabularyId);
6613
6614 if (!pagination) {
6615 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6616 start, end, false);
6617
6618 Collections.sort(list);
6619
6620 list = new UnmodifiableList<AssetCategory>(list);
6621 }
6622 else {
6623 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6624 start, end);
6625 }
6626
6627 cacheResult(list);
6628
6629 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6630 }
6631 catch (Exception e) {
6632 FinderCacheUtil.removeResult(finderPath, finderArgs);
6633
6634 throw processException(e);
6635 }
6636 finally {
6637 closeSession(session);
6638 }
6639 }
6640
6641 return list;
6642 }
6643
6644
6655 @Override
6656 public AssetCategory findByG_P_V_First(long groupId, long parentCategoryId,
6657 long vocabularyId, OrderByComparator orderByComparator)
6658 throws NoSuchCategoryException, SystemException {
6659 AssetCategory assetCategory = fetchByG_P_V_First(groupId,
6660 parentCategoryId, vocabularyId, orderByComparator);
6661
6662 if (assetCategory != null) {
6663 return assetCategory;
6664 }
6665
6666 StringBundler msg = new StringBundler(8);
6667
6668 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6669
6670 msg.append("groupId=");
6671 msg.append(groupId);
6672
6673 msg.append(", parentCategoryId=");
6674 msg.append(parentCategoryId);
6675
6676 msg.append(", vocabularyId=");
6677 msg.append(vocabularyId);
6678
6679 msg.append(StringPool.CLOSE_CURLY_BRACE);
6680
6681 throw new NoSuchCategoryException(msg.toString());
6682 }
6683
6684
6694 @Override
6695 public AssetCategory fetchByG_P_V_First(long groupId,
6696 long parentCategoryId, long vocabularyId,
6697 OrderByComparator orderByComparator) throws SystemException {
6698 List<AssetCategory> list = findByG_P_V(groupId, parentCategoryId,
6699 vocabularyId, 0, 1, orderByComparator);
6700
6701 if (!list.isEmpty()) {
6702 return list.get(0);
6703 }
6704
6705 return null;
6706 }
6707
6708
6719 @Override
6720 public AssetCategory findByG_P_V_Last(long groupId, long parentCategoryId,
6721 long vocabularyId, OrderByComparator orderByComparator)
6722 throws NoSuchCategoryException, SystemException {
6723 AssetCategory assetCategory = fetchByG_P_V_Last(groupId,
6724 parentCategoryId, vocabularyId, orderByComparator);
6725
6726 if (assetCategory != null) {
6727 return assetCategory;
6728 }
6729
6730 StringBundler msg = new StringBundler(8);
6731
6732 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6733
6734 msg.append("groupId=");
6735 msg.append(groupId);
6736
6737 msg.append(", parentCategoryId=");
6738 msg.append(parentCategoryId);
6739
6740 msg.append(", vocabularyId=");
6741 msg.append(vocabularyId);
6742
6743 msg.append(StringPool.CLOSE_CURLY_BRACE);
6744
6745 throw new NoSuchCategoryException(msg.toString());
6746 }
6747
6748
6758 @Override
6759 public AssetCategory fetchByG_P_V_Last(long groupId, long parentCategoryId,
6760 long vocabularyId, OrderByComparator orderByComparator)
6761 throws SystemException {
6762 int count = countByG_P_V(groupId, parentCategoryId, vocabularyId);
6763
6764 if (count == 0) {
6765 return null;
6766 }
6767
6768 List<AssetCategory> list = findByG_P_V(groupId, parentCategoryId,
6769 vocabularyId, count - 1, count, orderByComparator);
6770
6771 if (!list.isEmpty()) {
6772 return list.get(0);
6773 }
6774
6775 return null;
6776 }
6777
6778
6790 @Override
6791 public AssetCategory[] findByG_P_V_PrevAndNext(long categoryId,
6792 long groupId, long parentCategoryId, long vocabularyId,
6793 OrderByComparator orderByComparator)
6794 throws NoSuchCategoryException, SystemException {
6795 AssetCategory assetCategory = findByPrimaryKey(categoryId);
6796
6797 Session session = null;
6798
6799 try {
6800 session = openSession();
6801
6802 AssetCategory[] array = new AssetCategoryImpl[3];
6803
6804 array[0] = getByG_P_V_PrevAndNext(session, assetCategory, groupId,
6805 parentCategoryId, vocabularyId, orderByComparator, true);
6806
6807 array[1] = assetCategory;
6808
6809 array[2] = getByG_P_V_PrevAndNext(session, assetCategory, groupId,
6810 parentCategoryId, vocabularyId, orderByComparator, false);
6811
6812 return array;
6813 }
6814 catch (Exception e) {
6815 throw processException(e);
6816 }
6817 finally {
6818 closeSession(session);
6819 }
6820 }
6821
6822 protected AssetCategory getByG_P_V_PrevAndNext(Session session,
6823 AssetCategory assetCategory, long groupId, long parentCategoryId,
6824 long vocabularyId, OrderByComparator orderByComparator, boolean previous) {
6825 StringBundler query = null;
6826
6827 if (orderByComparator != null) {
6828 query = new StringBundler(6 +
6829 (orderByComparator.getOrderByFields().length * 6));
6830 }
6831 else {
6832 query = new StringBundler(3);
6833 }
6834
6835 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6836
6837 query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
6838
6839 query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
6840
6841 query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
6842
6843 if (orderByComparator != null) {
6844 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6845
6846 if (orderByConditionFields.length > 0) {
6847 query.append(WHERE_AND);
6848 }
6849
6850 for (int i = 0; i < orderByConditionFields.length; i++) {
6851 query.append(_ORDER_BY_ENTITY_ALIAS);
6852 query.append(orderByConditionFields[i]);
6853
6854 if ((i + 1) < orderByConditionFields.length) {
6855 if (orderByComparator.isAscending() ^ previous) {
6856 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6857 }
6858 else {
6859 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6860 }
6861 }
6862 else {
6863 if (orderByComparator.isAscending() ^ previous) {
6864 query.append(WHERE_GREATER_THAN);
6865 }
6866 else {
6867 query.append(WHERE_LESSER_THAN);
6868 }
6869 }
6870 }
6871
6872 query.append(ORDER_BY_CLAUSE);
6873
6874 String[] orderByFields = orderByComparator.getOrderByFields();
6875
6876 for (int i = 0; i < orderByFields.length; i++) {
6877 query.append(_ORDER_BY_ENTITY_ALIAS);
6878 query.append(orderByFields[i]);
6879
6880 if ((i + 1) < orderByFields.length) {
6881 if (orderByComparator.isAscending() ^ previous) {
6882 query.append(ORDER_BY_ASC_HAS_NEXT);
6883 }
6884 else {
6885 query.append(ORDER_BY_DESC_HAS_NEXT);
6886 }
6887 }
6888 else {
6889 if (orderByComparator.isAscending() ^ previous) {
6890 query.append(ORDER_BY_ASC);
6891 }
6892 else {
6893 query.append(ORDER_BY_DESC);
6894 }
6895 }
6896 }
6897 }
6898 else {
6899 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6900 }
6901
6902 String sql = query.toString();
6903
6904 Query q = session.createQuery(sql);
6905
6906 q.setFirstResult(0);
6907 q.setMaxResults(2);
6908
6909 QueryPos qPos = QueryPos.getInstance(q);
6910
6911 qPos.add(groupId);
6912
6913 qPos.add(parentCategoryId);
6914
6915 qPos.add(vocabularyId);
6916
6917 if (orderByComparator != null) {
6918 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6919
6920 for (Object value : values) {
6921 qPos.add(value);
6922 }
6923 }
6924
6925 List<AssetCategory> list = q.list();
6926
6927 if (list.size() == 2) {
6928 return list.get(1);
6929 }
6930 else {
6931 return null;
6932 }
6933 }
6934
6935
6944 @Override
6945 public List<AssetCategory> filterFindByG_P_V(long groupId,
6946 long parentCategoryId, long vocabularyId) throws SystemException {
6947 return filterFindByG_P_V(groupId, parentCategoryId, vocabularyId,
6948 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6949 }
6950
6951
6966 @Override
6967 public List<AssetCategory> filterFindByG_P_V(long groupId,
6968 long parentCategoryId, long vocabularyId, int start, int end)
6969 throws SystemException {
6970 return filterFindByG_P_V(groupId, parentCategoryId, vocabularyId,
6971 start, end, null);
6972 }
6973
6974
6990 @Override
6991 public List<AssetCategory> filterFindByG_P_V(long groupId,
6992 long parentCategoryId, long vocabularyId, int start, int end,
6993 OrderByComparator orderByComparator) throws SystemException {
6994 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6995 return findByG_P_V(groupId, parentCategoryId, vocabularyId, start,
6996 end, orderByComparator);
6997 }
6998
6999 StringBundler query = null;
7000
7001 if (orderByComparator != null) {
7002 query = new StringBundler(5 +
7003 (orderByComparator.getOrderByFields().length * 3));
7004 }
7005 else {
7006 query = new StringBundler(5);
7007 }
7008
7009 if (getDB().isSupportsInlineDistinct()) {
7010 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
7011 }
7012 else {
7013 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7014 }
7015
7016 query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7017
7018 query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7019
7020 query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7021
7022 if (!getDB().isSupportsInlineDistinct()) {
7023 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7024 }
7025
7026 if (orderByComparator != null) {
7027 if (getDB().isSupportsInlineDistinct()) {
7028 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7029 orderByComparator, true);
7030 }
7031 else {
7032 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7033 orderByComparator, true);
7034 }
7035 }
7036 else {
7037 if (getDB().isSupportsInlineDistinct()) {
7038 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7039 }
7040 else {
7041 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
7042 }
7043 }
7044
7045 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7046 AssetCategory.class.getName(),
7047 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7048
7049 Session session = null;
7050
7051 try {
7052 session = openSession();
7053
7054 SQLQuery q = session.createSQLQuery(sql);
7055
7056 if (getDB().isSupportsInlineDistinct()) {
7057 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
7058 }
7059 else {
7060 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
7061 }
7062
7063 QueryPos qPos = QueryPos.getInstance(q);
7064
7065 qPos.add(groupId);
7066
7067 qPos.add(parentCategoryId);
7068
7069 qPos.add(vocabularyId);
7070
7071 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
7072 end);
7073 }
7074 catch (Exception e) {
7075 throw processException(e);
7076 }
7077 finally {
7078 closeSession(session);
7079 }
7080 }
7081
7082
7094 @Override
7095 public AssetCategory[] filterFindByG_P_V_PrevAndNext(long categoryId,
7096 long groupId, long parentCategoryId, long vocabularyId,
7097 OrderByComparator orderByComparator)
7098 throws NoSuchCategoryException, SystemException {
7099 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7100 return findByG_P_V_PrevAndNext(categoryId, groupId,
7101 parentCategoryId, vocabularyId, orderByComparator);
7102 }
7103
7104 AssetCategory assetCategory = findByPrimaryKey(categoryId);
7105
7106 Session session = null;
7107
7108 try {
7109 session = openSession();
7110
7111 AssetCategory[] array = new AssetCategoryImpl[3];
7112
7113 array[0] = filterGetByG_P_V_PrevAndNext(session, assetCategory,
7114 groupId, parentCategoryId, vocabularyId, orderByComparator,
7115 true);
7116
7117 array[1] = assetCategory;
7118
7119 array[2] = filterGetByG_P_V_PrevAndNext(session, assetCategory,
7120 groupId, parentCategoryId, vocabularyId, orderByComparator,
7121 false);
7122
7123 return array;
7124 }
7125 catch (Exception e) {
7126 throw processException(e);
7127 }
7128 finally {
7129 closeSession(session);
7130 }
7131 }
7132
7133 protected AssetCategory filterGetByG_P_V_PrevAndNext(Session session,
7134 AssetCategory assetCategory, long groupId, long parentCategoryId,
7135 long vocabularyId, OrderByComparator orderByComparator, boolean previous) {
7136 StringBundler query = null;
7137
7138 if (orderByComparator != null) {
7139 query = new StringBundler(6 +
7140 (orderByComparator.getOrderByFields().length * 6));
7141 }
7142 else {
7143 query = new StringBundler(3);
7144 }
7145
7146 if (getDB().isSupportsInlineDistinct()) {
7147 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
7148 }
7149 else {
7150 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7151 }
7152
7153 query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7154
7155 query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7156
7157 query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7158
7159 if (!getDB().isSupportsInlineDistinct()) {
7160 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7161 }
7162
7163 if (orderByComparator != null) {
7164 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7165
7166 if (orderByConditionFields.length > 0) {
7167 query.append(WHERE_AND);
7168 }
7169
7170 for (int i = 0; i < orderByConditionFields.length; i++) {
7171 if (getDB().isSupportsInlineDistinct()) {
7172 query.append(_ORDER_BY_ENTITY_ALIAS);
7173 }
7174 else {
7175 query.append(_ORDER_BY_ENTITY_TABLE);
7176 }
7177
7178 query.append(orderByConditionFields[i]);
7179
7180 if ((i + 1) < orderByConditionFields.length) {
7181 if (orderByComparator.isAscending() ^ previous) {
7182 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7183 }
7184 else {
7185 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7186 }
7187 }
7188 else {
7189 if (orderByComparator.isAscending() ^ previous) {
7190 query.append(WHERE_GREATER_THAN);
7191 }
7192 else {
7193 query.append(WHERE_LESSER_THAN);
7194 }
7195 }
7196 }
7197
7198 query.append(ORDER_BY_CLAUSE);
7199
7200 String[] orderByFields = orderByComparator.getOrderByFields();
7201
7202 for (int i = 0; i < orderByFields.length; i++) {
7203 if (getDB().isSupportsInlineDistinct()) {
7204 query.append(_ORDER_BY_ENTITY_ALIAS);
7205 }
7206 else {
7207 query.append(_ORDER_BY_ENTITY_TABLE);
7208 }
7209
7210 query.append(orderByFields[i]);
7211
7212 if ((i + 1) < orderByFields.length) {
7213 if (orderByComparator.isAscending() ^ previous) {
7214 query.append(ORDER_BY_ASC_HAS_NEXT);
7215 }
7216 else {
7217 query.append(ORDER_BY_DESC_HAS_NEXT);
7218 }
7219 }
7220 else {
7221 if (orderByComparator.isAscending() ^ previous) {
7222 query.append(ORDER_BY_ASC);
7223 }
7224 else {
7225 query.append(ORDER_BY_DESC);
7226 }
7227 }
7228 }
7229 }
7230 else {
7231 if (getDB().isSupportsInlineDistinct()) {
7232 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7233 }
7234 else {
7235 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
7236 }
7237 }
7238
7239 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7240 AssetCategory.class.getName(),
7241 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7242
7243 SQLQuery q = session.createSQLQuery(sql);
7244
7245 q.setFirstResult(0);
7246 q.setMaxResults(2);
7247
7248 if (getDB().isSupportsInlineDistinct()) {
7249 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
7250 }
7251 else {
7252 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
7253 }
7254
7255 QueryPos qPos = QueryPos.getInstance(q);
7256
7257 qPos.add(groupId);
7258
7259 qPos.add(parentCategoryId);
7260
7261 qPos.add(vocabularyId);
7262
7263 if (orderByComparator != null) {
7264 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
7265
7266 for (Object value : values) {
7267 qPos.add(value);
7268 }
7269 }
7270
7271 List<AssetCategory> list = q.list();
7272
7273 if (list.size() == 2) {
7274 return list.get(1);
7275 }
7276 else {
7277 return null;
7278 }
7279 }
7280
7281
7289 @Override
7290 public void removeByG_P_V(long groupId, long parentCategoryId,
7291 long vocabularyId) throws SystemException {
7292 for (AssetCategory assetCategory : findByG_P_V(groupId,
7293 parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
7294 QueryUtil.ALL_POS, null)) {
7295 remove(assetCategory);
7296 }
7297 }
7298
7299
7308 @Override
7309 public int countByG_P_V(long groupId, long parentCategoryId,
7310 long vocabularyId) throws SystemException {
7311 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_V;
7312
7313 Object[] finderArgs = new Object[] {
7314 groupId, parentCategoryId, vocabularyId
7315 };
7316
7317 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7318 this);
7319
7320 if (count == null) {
7321 StringBundler query = new StringBundler(4);
7322
7323 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
7324
7325 query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7326
7327 query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7328
7329 query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7330
7331 String sql = query.toString();
7332
7333 Session session = null;
7334
7335 try {
7336 session = openSession();
7337
7338 Query q = session.createQuery(sql);
7339
7340 QueryPos qPos = QueryPos.getInstance(q);
7341
7342 qPos.add(groupId);
7343
7344 qPos.add(parentCategoryId);
7345
7346 qPos.add(vocabularyId);
7347
7348 count = (Long)q.uniqueResult();
7349
7350 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7351 }
7352 catch (Exception e) {
7353 FinderCacheUtil.removeResult(finderPath, finderArgs);
7354
7355 throw processException(e);
7356 }
7357 finally {
7358 closeSession(session);
7359 }
7360 }
7361
7362 return count.intValue();
7363 }
7364
7365
7374 @Override
7375 public int filterCountByG_P_V(long groupId, long parentCategoryId,
7376 long vocabularyId) throws SystemException {
7377 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7378 return countByG_P_V(groupId, parentCategoryId, vocabularyId);
7379 }
7380
7381 StringBundler query = new StringBundler(4);
7382
7383 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
7384
7385 query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7386
7387 query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7388
7389 query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7390
7391 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7392 AssetCategory.class.getName(),
7393 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7394
7395 Session session = null;
7396
7397 try {
7398 session = openSession();
7399
7400 SQLQuery q = session.createSQLQuery(sql);
7401
7402 q.addScalar(COUNT_COLUMN_NAME,
7403 com.liferay.portal.kernel.dao.orm.Type.LONG);
7404
7405 QueryPos qPos = QueryPos.getInstance(q);
7406
7407 qPos.add(groupId);
7408
7409 qPos.add(parentCategoryId);
7410
7411 qPos.add(vocabularyId);
7412
7413 Long count = (Long)q.uniqueResult();
7414
7415 return count.intValue();
7416 }
7417 catch (Exception e) {
7418 throw processException(e);
7419 }
7420 finally {
7421 closeSession(session);
7422 }
7423 }
7424
7425 private static final String _FINDER_COLUMN_G_P_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
7426 private static final String _FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
7427 private static final String _FINDER_COLUMN_G_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
7428 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V =
7429 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7430 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
7431 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
7432 "findByG_LikeN_V",
7433 new String[] {
7434 Long.class.getName(), String.class.getName(),
7435 Long.class.getName(),
7436
7437 Integer.class.getName(), Integer.class.getName(),
7438 OrderByComparator.class.getName()
7439 });
7440 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V =
7441 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7442 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
7443 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LikeN_V",
7444 new String[] {
7445 Long.class.getName(), String.class.getName(),
7446 Long.class.getName()
7447 });
7448
7449
7458 @Override
7459 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7460 long vocabularyId) throws SystemException {
7461 return findByG_LikeN_V(groupId, name, vocabularyId, QueryUtil.ALL_POS,
7462 QueryUtil.ALL_POS, null);
7463 }
7464
7465
7480 @Override
7481 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7482 long vocabularyId, int start, int end) throws SystemException {
7483 return findByG_LikeN_V(groupId, name, vocabularyId, start, end, null);
7484 }
7485
7486
7502 @Override
7503 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7504 long vocabularyId, int start, int end,
7505 OrderByComparator orderByComparator) throws SystemException {
7506 boolean pagination = true;
7507 FinderPath finderPath = null;
7508 Object[] finderArgs = null;
7509
7510 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V;
7511 finderArgs = new Object[] {
7512 groupId, name, vocabularyId,
7513
7514 start, end, orderByComparator
7515 };
7516
7517 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
7518 finderArgs, this);
7519
7520 if ((list != null) && !list.isEmpty()) {
7521 for (AssetCategory assetCategory : list) {
7522 if ((groupId != assetCategory.getGroupId()) ||
7523 !StringUtil.wildcardMatches(assetCategory.getName(),
7524 name, CharPool.UNDERLINE, CharPool.PERCENT,
7525 CharPool.BACK_SLASH, false) ||
7526 (vocabularyId != assetCategory.getVocabularyId())) {
7527 list = null;
7528
7529 break;
7530 }
7531 }
7532 }
7533
7534 if (list == null) {
7535 StringBundler query = null;
7536
7537 if (orderByComparator != null) {
7538 query = new StringBundler(5 +
7539 (orderByComparator.getOrderByFields().length * 3));
7540 }
7541 else {
7542 query = new StringBundler(5);
7543 }
7544
7545 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
7546
7547 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7548
7549 boolean bindName = false;
7550
7551 if (name == null) {
7552 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7553 }
7554 else if (name.equals(StringPool.BLANK)) {
7555 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7556 }
7557 else {
7558 bindName = true;
7559
7560 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7561 }
7562
7563 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7564
7565 if (orderByComparator != null) {
7566 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7567 orderByComparator);
7568 }
7569 else
7570 if (pagination) {
7571 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7572 }
7573
7574 String sql = query.toString();
7575
7576 Session session = null;
7577
7578 try {
7579 session = openSession();
7580
7581 Query q = session.createQuery(sql);
7582
7583 QueryPos qPos = QueryPos.getInstance(q);
7584
7585 qPos.add(groupId);
7586
7587 if (bindName) {
7588 qPos.add(name.toLowerCase());
7589 }
7590
7591 qPos.add(vocabularyId);
7592
7593 if (!pagination) {
7594 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7595 start, end, false);
7596
7597 Collections.sort(list);
7598
7599 list = new UnmodifiableList<AssetCategory>(list);
7600 }
7601 else {
7602 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7603 start, end);
7604 }
7605
7606 cacheResult(list);
7607
7608 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7609 }
7610 catch (Exception e) {
7611 FinderCacheUtil.removeResult(finderPath, finderArgs);
7612
7613 throw processException(e);
7614 }
7615 finally {
7616 closeSession(session);
7617 }
7618 }
7619
7620 return list;
7621 }
7622
7623
7634 @Override
7635 public AssetCategory findByG_LikeN_V_First(long groupId, String name,
7636 long vocabularyId, OrderByComparator orderByComparator)
7637 throws NoSuchCategoryException, SystemException {
7638 AssetCategory assetCategory = fetchByG_LikeN_V_First(groupId, name,
7639 vocabularyId, orderByComparator);
7640
7641 if (assetCategory != null) {
7642 return assetCategory;
7643 }
7644
7645 StringBundler msg = new StringBundler(8);
7646
7647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7648
7649 msg.append("groupId=");
7650 msg.append(groupId);
7651
7652 msg.append(", name=");
7653 msg.append(name);
7654
7655 msg.append(", vocabularyId=");
7656 msg.append(vocabularyId);
7657
7658 msg.append(StringPool.CLOSE_CURLY_BRACE);
7659
7660 throw new NoSuchCategoryException(msg.toString());
7661 }
7662
7663
7673 @Override
7674 public AssetCategory fetchByG_LikeN_V_First(long groupId, String name,
7675 long vocabularyId, OrderByComparator orderByComparator)
7676 throws SystemException {
7677 List<AssetCategory> list = findByG_LikeN_V(groupId, name, vocabularyId,
7678 0, 1, orderByComparator);
7679
7680 if (!list.isEmpty()) {
7681 return list.get(0);
7682 }
7683
7684 return null;
7685 }
7686
7687
7698 @Override
7699 public AssetCategory findByG_LikeN_V_Last(long groupId, String name,
7700 long vocabularyId, OrderByComparator orderByComparator)
7701 throws NoSuchCategoryException, SystemException {
7702 AssetCategory assetCategory = fetchByG_LikeN_V_Last(groupId, name,
7703 vocabularyId, orderByComparator);
7704
7705 if (assetCategory != null) {
7706 return assetCategory;
7707 }
7708
7709 StringBundler msg = new StringBundler(8);
7710
7711 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7712
7713 msg.append("groupId=");
7714 msg.append(groupId);
7715
7716 msg.append(", name=");
7717 msg.append(name);
7718
7719 msg.append(", vocabularyId=");
7720 msg.append(vocabularyId);
7721
7722 msg.append(StringPool.CLOSE_CURLY_BRACE);
7723
7724 throw new NoSuchCategoryException(msg.toString());
7725 }
7726
7727
7737 @Override
7738 public AssetCategory fetchByG_LikeN_V_Last(long groupId, String name,
7739 long vocabularyId, OrderByComparator orderByComparator)
7740 throws SystemException {
7741 int count = countByG_LikeN_V(groupId, name, vocabularyId);
7742
7743 if (count == 0) {
7744 return null;
7745 }
7746
7747 List<AssetCategory> list = findByG_LikeN_V(groupId, name, vocabularyId,
7748 count - 1, count, orderByComparator);
7749
7750 if (!list.isEmpty()) {
7751 return list.get(0);
7752 }
7753
7754 return null;
7755 }
7756
7757
7769 @Override
7770 public AssetCategory[] findByG_LikeN_V_PrevAndNext(long categoryId,
7771 long groupId, String name, long vocabularyId,
7772 OrderByComparator orderByComparator)
7773 throws NoSuchCategoryException, SystemException {
7774 AssetCategory assetCategory = findByPrimaryKey(categoryId);
7775
7776 Session session = null;
7777
7778 try {
7779 session = openSession();
7780
7781 AssetCategory[] array = new AssetCategoryImpl[3];
7782
7783 array[0] = getByG_LikeN_V_PrevAndNext(session, assetCategory,
7784 groupId, name, vocabularyId, orderByComparator, true);
7785
7786 array[1] = assetCategory;
7787
7788 array[2] = getByG_LikeN_V_PrevAndNext(session, assetCategory,
7789 groupId, name, vocabularyId, orderByComparator, false);
7790
7791 return array;
7792 }
7793 catch (Exception e) {
7794 throw processException(e);
7795 }
7796 finally {
7797 closeSession(session);
7798 }
7799 }
7800
7801 protected AssetCategory getByG_LikeN_V_PrevAndNext(Session session,
7802 AssetCategory assetCategory, long groupId, String name,
7803 long vocabularyId, OrderByComparator orderByComparator, boolean previous) {
7804 StringBundler query = null;
7805
7806 if (orderByComparator != null) {
7807 query = new StringBundler(6 +
7808 (orderByComparator.getOrderByFields().length * 6));
7809 }
7810 else {
7811 query = new StringBundler(3);
7812 }
7813
7814 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
7815
7816 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7817
7818 boolean bindName = false;
7819
7820 if (name == null) {
7821 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7822 }
7823 else if (name.equals(StringPool.BLANK)) {
7824 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7825 }
7826 else {
7827 bindName = true;
7828
7829 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7830 }
7831
7832 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7833
7834 if (orderByComparator != null) {
7835 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7836
7837 if (orderByConditionFields.length > 0) {
7838 query.append(WHERE_AND);
7839 }
7840
7841 for (int i = 0; i < orderByConditionFields.length; i++) {
7842 query.append(_ORDER_BY_ENTITY_ALIAS);
7843 query.append(orderByConditionFields[i]);
7844
7845 if ((i + 1) < orderByConditionFields.length) {
7846 if (orderByComparator.isAscending() ^ previous) {
7847 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7848 }
7849 else {
7850 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7851 }
7852 }
7853 else {
7854 if (orderByComparator.isAscending() ^ previous) {
7855 query.append(WHERE_GREATER_THAN);
7856 }
7857 else {
7858 query.append(WHERE_LESSER_THAN);
7859 }
7860 }
7861 }
7862
7863 query.append(ORDER_BY_CLAUSE);
7864
7865 String[] orderByFields = orderByComparator.getOrderByFields();
7866
7867 for (int i = 0; i < orderByFields.length; i++) {
7868 query.append(_ORDER_BY_ENTITY_ALIAS);
7869 query.append(orderByFields[i]);
7870
7871 if ((i + 1) < orderByFields.length) {
7872 if (orderByComparator.isAscending() ^ previous) {
7873 query.append(ORDER_BY_ASC_HAS_NEXT);
7874 }
7875 else {
7876 query.append(ORDER_BY_DESC_HAS_NEXT);
7877 }
7878 }
7879 else {
7880 if (orderByComparator.isAscending() ^ previous) {
7881 query.append(ORDER_BY_ASC);
7882 }
7883 else {
7884 query.append(ORDER_BY_DESC);
7885 }
7886 }
7887 }
7888 }
7889 else {
7890 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7891 }
7892
7893 String sql = query.toString();
7894
7895 Query q = session.createQuery(sql);
7896
7897 q.setFirstResult(0);
7898 q.setMaxResults(2);
7899
7900 QueryPos qPos = QueryPos.getInstance(q);
7901
7902 qPos.add(groupId);
7903
7904 if (bindName) {
7905 qPos.add(name.toLowerCase());
7906 }
7907
7908 qPos.add(vocabularyId);
7909
7910 if (orderByComparator != null) {
7911 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
7912
7913 for (Object value : values) {
7914 qPos.add(value);
7915 }
7916 }
7917
7918 List<AssetCategory> list = q.list();
7919
7920 if (list.size() == 2) {
7921 return list.get(1);
7922 }
7923 else {
7924 return null;
7925 }
7926 }
7927
7928
7937 @Override
7938 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
7939 long vocabularyId) throws SystemException {
7940 return filterFindByG_LikeN_V(groupId, name, vocabularyId,
7941 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7942 }
7943
7944
7959 @Override
7960 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
7961 long vocabularyId, int start, int end) throws SystemException {
7962 return filterFindByG_LikeN_V(groupId, name, vocabularyId, start, end,
7963 null);
7964 }
7965
7966
7982 @Override
7983 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
7984 long vocabularyId, int start, int end,
7985 OrderByComparator orderByComparator) throws SystemException {
7986 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7987 return findByG_LikeN_V(groupId, name, vocabularyId, start, end,
7988 orderByComparator);
7989 }
7990
7991 StringBundler query = null;
7992
7993 if (orderByComparator != null) {
7994 query = new StringBundler(5 +
7995 (orderByComparator.getOrderByFields().length * 3));
7996 }
7997 else {
7998 query = new StringBundler(5);
7999 }
8000
8001 if (getDB().isSupportsInlineDistinct()) {
8002 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8003 }
8004 else {
8005 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8006 }
8007
8008 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8009
8010 boolean bindName = false;
8011
8012 if (name == null) {
8013 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8014 }
8015 else if (name.equals(StringPool.BLANK)) {
8016 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8017 }
8018 else {
8019 bindName = true;
8020
8021 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8022 }
8023
8024 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8025
8026 if (!getDB().isSupportsInlineDistinct()) {
8027 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8028 }
8029
8030 if (orderByComparator != null) {
8031 if (getDB().isSupportsInlineDistinct()) {
8032 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8033 orderByComparator, true);
8034 }
8035 else {
8036 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8037 orderByComparator, true);
8038 }
8039 }
8040 else {
8041 if (getDB().isSupportsInlineDistinct()) {
8042 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8043 }
8044 else {
8045 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8046 }
8047 }
8048
8049 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8050 AssetCategory.class.getName(),
8051 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8052
8053 Session session = null;
8054
8055 try {
8056 session = openSession();
8057
8058 SQLQuery q = session.createSQLQuery(sql);
8059
8060 if (getDB().isSupportsInlineDistinct()) {
8061 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8062 }
8063 else {
8064 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8065 }
8066
8067 QueryPos qPos = QueryPos.getInstance(q);
8068
8069 qPos.add(groupId);
8070
8071 if (bindName) {
8072 qPos.add(name.toLowerCase());
8073 }
8074
8075 qPos.add(vocabularyId);
8076
8077 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
8078 end);
8079 }
8080 catch (Exception e) {
8081 throw processException(e);
8082 }
8083 finally {
8084 closeSession(session);
8085 }
8086 }
8087
8088
8100 @Override
8101 public AssetCategory[] filterFindByG_LikeN_V_PrevAndNext(long categoryId,
8102 long groupId, String name, long vocabularyId,
8103 OrderByComparator orderByComparator)
8104 throws NoSuchCategoryException, SystemException {
8105 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8106 return findByG_LikeN_V_PrevAndNext(categoryId, groupId, name,
8107 vocabularyId, orderByComparator);
8108 }
8109
8110 AssetCategory assetCategory = findByPrimaryKey(categoryId);
8111
8112 Session session = null;
8113
8114 try {
8115 session = openSession();
8116
8117 AssetCategory[] array = new AssetCategoryImpl[3];
8118
8119 array[0] = filterGetByG_LikeN_V_PrevAndNext(session, assetCategory,
8120 groupId, name, vocabularyId, orderByComparator, true);
8121
8122 array[1] = assetCategory;
8123
8124 array[2] = filterGetByG_LikeN_V_PrevAndNext(session, assetCategory,
8125 groupId, name, vocabularyId, orderByComparator, false);
8126
8127 return array;
8128 }
8129 catch (Exception e) {
8130 throw processException(e);
8131 }
8132 finally {
8133 closeSession(session);
8134 }
8135 }
8136
8137 protected AssetCategory filterGetByG_LikeN_V_PrevAndNext(Session session,
8138 AssetCategory assetCategory, long groupId, String name,
8139 long vocabularyId, OrderByComparator orderByComparator, boolean previous) {
8140 StringBundler query = null;
8141
8142 if (orderByComparator != null) {
8143 query = new StringBundler(6 +
8144 (orderByComparator.getOrderByFields().length * 6));
8145 }
8146 else {
8147 query = new StringBundler(3);
8148 }
8149
8150 if (getDB().isSupportsInlineDistinct()) {
8151 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8152 }
8153 else {
8154 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8155 }
8156
8157 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8158
8159 boolean bindName = false;
8160
8161 if (name == null) {
8162 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8163 }
8164 else if (name.equals(StringPool.BLANK)) {
8165 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8166 }
8167 else {
8168 bindName = true;
8169
8170 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8171 }
8172
8173 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8174
8175 if (!getDB().isSupportsInlineDistinct()) {
8176 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8177 }
8178
8179 if (orderByComparator != null) {
8180 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8181
8182 if (orderByConditionFields.length > 0) {
8183 query.append(WHERE_AND);
8184 }
8185
8186 for (int i = 0; i < orderByConditionFields.length; i++) {
8187 if (getDB().isSupportsInlineDistinct()) {
8188 query.append(_ORDER_BY_ENTITY_ALIAS);
8189 }
8190 else {
8191 query.append(_ORDER_BY_ENTITY_TABLE);
8192 }
8193
8194 query.append(orderByConditionFields[i]);
8195
8196 if ((i + 1) < orderByConditionFields.length) {
8197 if (orderByComparator.isAscending() ^ previous) {
8198 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8199 }
8200 else {
8201 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8202 }
8203 }
8204 else {
8205 if (orderByComparator.isAscending() ^ previous) {
8206 query.append(WHERE_GREATER_THAN);
8207 }
8208 else {
8209 query.append(WHERE_LESSER_THAN);
8210 }
8211 }
8212 }
8213
8214 query.append(ORDER_BY_CLAUSE);
8215
8216 String[] orderByFields = orderByComparator.getOrderByFields();
8217
8218 for (int i = 0; i < orderByFields.length; i++) {
8219 if (getDB().isSupportsInlineDistinct()) {
8220 query.append(_ORDER_BY_ENTITY_ALIAS);
8221 }
8222 else {
8223 query.append(_ORDER_BY_ENTITY_TABLE);
8224 }
8225
8226 query.append(orderByFields[i]);
8227
8228 if ((i + 1) < orderByFields.length) {
8229 if (orderByComparator.isAscending() ^ previous) {
8230 query.append(ORDER_BY_ASC_HAS_NEXT);
8231 }
8232 else {
8233 query.append(ORDER_BY_DESC_HAS_NEXT);
8234 }
8235 }
8236 else {
8237 if (orderByComparator.isAscending() ^ previous) {
8238 query.append(ORDER_BY_ASC);
8239 }
8240 else {
8241 query.append(ORDER_BY_DESC);
8242 }
8243 }
8244 }
8245 }
8246 else {
8247 if (getDB().isSupportsInlineDistinct()) {
8248 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8249 }
8250 else {
8251 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8252 }
8253 }
8254
8255 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8256 AssetCategory.class.getName(),
8257 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8258
8259 SQLQuery q = session.createSQLQuery(sql);
8260
8261 q.setFirstResult(0);
8262 q.setMaxResults(2);
8263
8264 if (getDB().isSupportsInlineDistinct()) {
8265 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8266 }
8267 else {
8268 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8269 }
8270
8271 QueryPos qPos = QueryPos.getInstance(q);
8272
8273 qPos.add(groupId);
8274
8275 if (bindName) {
8276 qPos.add(name.toLowerCase());
8277 }
8278
8279 qPos.add(vocabularyId);
8280
8281 if (orderByComparator != null) {
8282 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
8283
8284 for (Object value : values) {
8285 qPos.add(value);
8286 }
8287 }
8288
8289 List<AssetCategory> list = q.list();
8290
8291 if (list.size() == 2) {
8292 return list.get(1);
8293 }
8294 else {
8295 return null;
8296 }
8297 }
8298
8299
8308 @Override
8309 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8310 long[] vocabularyIds) throws SystemException {
8311 return filterFindByG_LikeN_V(groupId, name, vocabularyIds,
8312 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8313 }
8314
8315
8330 @Override
8331 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8332 long[] vocabularyIds, int start, int end) throws SystemException {
8333 return filterFindByG_LikeN_V(groupId, name, vocabularyIds, start, end,
8334 null);
8335 }
8336
8337
8353 @Override
8354 public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8355 long[] vocabularyIds, int start, int end,
8356 OrderByComparator orderByComparator) throws SystemException {
8357 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8358 return findByG_LikeN_V(groupId, name, vocabularyIds, start, end,
8359 orderByComparator);
8360 }
8361
8362 StringBundler query = new StringBundler();
8363
8364 if (getDB().isSupportsInlineDistinct()) {
8365 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8366 }
8367 else {
8368 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8369 }
8370
8371 boolean conjunctionable = false;
8372
8373 if (conjunctionable) {
8374 query.append(WHERE_AND);
8375 }
8376
8377 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
8378
8379 conjunctionable = true;
8380
8381 if (conjunctionable) {
8382 query.append(WHERE_AND);
8383 }
8384
8385 boolean bindName = false;
8386
8387 if (name == null) {
8388 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
8389 }
8390 else if (name.equals(StringPool.BLANK)) {
8391 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
8392 }
8393 else {
8394 bindName = true;
8395
8396 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
8397 }
8398
8399 conjunctionable = true;
8400
8401 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
8402 if (conjunctionable) {
8403 query.append(WHERE_AND);
8404 }
8405
8406 query.append(StringPool.OPEN_PARENTHESIS);
8407
8408 for (int i = 0; i < vocabularyIds.length; i++) {
8409 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
8410
8411 if ((i + 1) < vocabularyIds.length) {
8412 query.append(WHERE_OR);
8413 }
8414 }
8415
8416 query.append(StringPool.CLOSE_PARENTHESIS);
8417
8418 conjunctionable = true;
8419 }
8420
8421 if (!getDB().isSupportsInlineDistinct()) {
8422 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8423 }
8424
8425 if (orderByComparator != null) {
8426 if (getDB().isSupportsInlineDistinct()) {
8427 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8428 orderByComparator, true);
8429 }
8430 else {
8431 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8432 orderByComparator, true);
8433 }
8434 }
8435 else {
8436 if (getDB().isSupportsInlineDistinct()) {
8437 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8438 }
8439 else {
8440 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8441 }
8442 }
8443
8444 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8445 AssetCategory.class.getName(),
8446 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8447
8448 Session session = null;
8449
8450 try {
8451 session = openSession();
8452
8453 SQLQuery q = session.createSQLQuery(sql);
8454
8455 if (getDB().isSupportsInlineDistinct()) {
8456 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8457 }
8458 else {
8459 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8460 }
8461
8462 QueryPos qPos = QueryPos.getInstance(q);
8463
8464 qPos.add(groupId);
8465
8466 if (bindName) {
8467 qPos.add(name);
8468 }
8469
8470 if (vocabularyIds != null) {
8471 qPos.add(vocabularyIds);
8472 }
8473
8474 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
8475 end);
8476 }
8477 catch (Exception e) {
8478 throw processException(e);
8479 }
8480 finally {
8481 closeSession(session);
8482 }
8483 }
8484
8485
8498 @Override
8499 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8500 long[] vocabularyIds) throws SystemException {
8501 return findByG_LikeN_V(groupId, name, vocabularyIds, QueryUtil.ALL_POS,
8502 QueryUtil.ALL_POS, null);
8503 }
8504
8505
8520 @Override
8521 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8522 long[] vocabularyIds, int start, int end) throws SystemException {
8523 return findByG_LikeN_V(groupId, name, vocabularyIds, start, end, null);
8524 }
8525
8526
8542 @Override
8543 public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8544 long[] vocabularyIds, int start, int end,
8545 OrderByComparator orderByComparator) throws SystemException {
8546 if ((vocabularyIds != null) && (vocabularyIds.length == 1)) {
8547 return findByG_LikeN_V(groupId, name, vocabularyIds[0], start, end,
8548 orderByComparator);
8549 }
8550
8551 boolean pagination = true;
8552 Object[] finderArgs = null;
8553
8554 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8555 (orderByComparator == null)) {
8556 pagination = false;
8557 finderArgs = new Object[] {
8558 groupId, name, StringUtil.merge(vocabularyIds)
8559 };
8560 }
8561 else {
8562 finderArgs = new Object[] {
8563 groupId, name, StringUtil.merge(vocabularyIds),
8564
8565 start, end, orderByComparator
8566 };
8567 }
8568
8569 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
8570 finderArgs, this);
8571
8572 if ((list != null) && !list.isEmpty()) {
8573 for (AssetCategory assetCategory : list) {
8574 if ((groupId != assetCategory.getGroupId()) ||
8575 !Validator.equals(name, assetCategory.getName()) ||
8576 !ArrayUtil.contains(vocabularyIds,
8577 assetCategory.getVocabularyId())) {
8578 list = null;
8579
8580 break;
8581 }
8582 }
8583 }
8584
8585 if (list == null) {
8586 StringBundler query = new StringBundler();
8587
8588 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
8589
8590 boolean conjunctionable = false;
8591
8592 if (conjunctionable) {
8593 query.append(WHERE_AND);
8594 }
8595
8596 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
8597
8598 conjunctionable = true;
8599
8600 if (conjunctionable) {
8601 query.append(WHERE_AND);
8602 }
8603
8604 boolean bindName = false;
8605
8606 if (name == null) {
8607 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
8608 }
8609 else if (name.equals(StringPool.BLANK)) {
8610 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
8611 }
8612 else {
8613 bindName = true;
8614
8615 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
8616 }
8617
8618 conjunctionable = true;
8619
8620 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
8621 if (conjunctionable) {
8622 query.append(WHERE_AND);
8623 }
8624
8625 query.append(StringPool.OPEN_PARENTHESIS);
8626
8627 for (int i = 0; i < vocabularyIds.length; i++) {
8628 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
8629
8630 if ((i + 1) < vocabularyIds.length) {
8631 query.append(WHERE_OR);
8632 }
8633 }
8634
8635 query.append(StringPool.CLOSE_PARENTHESIS);
8636
8637 conjunctionable = true;
8638 }
8639
8640 if (orderByComparator != null) {
8641 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8642 orderByComparator);
8643 }
8644 else
8645 if (pagination) {
8646 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8647 }
8648
8649 String sql = query.toString();
8650
8651 Session session = null;
8652
8653 try {
8654 session = openSession();
8655
8656 Query q = session.createQuery(sql);
8657
8658 QueryPos qPos = QueryPos.getInstance(q);
8659
8660 qPos.add(groupId);
8661
8662 if (bindName) {
8663 qPos.add(name);
8664 }
8665
8666 if (vocabularyIds != null) {
8667 qPos.add(vocabularyIds);
8668 }
8669
8670 if (!pagination) {
8671 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
8672 start, end, false);
8673
8674 Collections.sort(list);
8675
8676 list = new UnmodifiableList<AssetCategory>(list);
8677 }
8678 else {
8679 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
8680 start, end);
8681 }
8682
8683 cacheResult(list);
8684
8685 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
8686 finderArgs, list);
8687 }
8688 catch (Exception e) {
8689 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
8690 finderArgs);
8691
8692 throw processException(e);
8693 }
8694 finally {
8695 closeSession(session);
8696 }
8697 }
8698
8699 return list;
8700 }
8701
8702
8710 @Override
8711 public void removeByG_LikeN_V(long groupId, String name, long vocabularyId)
8712 throws SystemException {
8713 for (AssetCategory assetCategory : findByG_LikeN_V(groupId, name,
8714 vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8715 remove(assetCategory);
8716 }
8717 }
8718
8719
8728 @Override
8729 public int countByG_LikeN_V(long groupId, String name, long vocabularyId)
8730 throws SystemException {
8731 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V;
8732
8733 Object[] finderArgs = new Object[] { groupId, name, vocabularyId };
8734
8735 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8736 this);
8737
8738 if (count == null) {
8739 StringBundler query = new StringBundler(4);
8740
8741 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
8742
8743 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8744
8745 boolean bindName = false;
8746
8747 if (name == null) {
8748 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8749 }
8750 else if (name.equals(StringPool.BLANK)) {
8751 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8752 }
8753 else {
8754 bindName = true;
8755
8756 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8757 }
8758
8759 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8760
8761 String sql = query.toString();
8762
8763 Session session = null;
8764
8765 try {
8766 session = openSession();
8767
8768 Query q = session.createQuery(sql);
8769
8770 QueryPos qPos = QueryPos.getInstance(q);
8771
8772 qPos.add(groupId);
8773
8774 if (bindName) {
8775 qPos.add(name.toLowerCase());
8776 }
8777
8778 qPos.add(vocabularyId);
8779
8780 count = (Long)q.uniqueResult();
8781
8782 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8783 }
8784 catch (Exception e) {
8785 FinderCacheUtil.removeResult(finderPath, finderArgs);
8786
8787 throw processException(e);
8788 }
8789 finally {
8790 closeSession(session);
8791 }
8792 }
8793
8794 return count.intValue();
8795 }
8796
8797
8806 @Override
8807 public int countByG_LikeN_V(long groupId, String name, long[] vocabularyIds)
8808 throws SystemException {
8809 Object[] finderArgs = new Object[] {
8810 groupId, name, StringUtil.merge(vocabularyIds)
8811 };
8812
8813 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
8814 finderArgs, this);
8815
8816 if (count == null) {
8817 StringBundler query = new StringBundler();
8818
8819 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
8820
8821 boolean conjunctionable = false;
8822
8823 if (conjunctionable) {
8824 query.append(WHERE_AND);
8825 }
8826
8827 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
8828
8829 conjunctionable = true;
8830
8831 if (conjunctionable) {
8832 query.append(WHERE_AND);
8833 }
8834
8835 boolean bindName = false;
8836
8837 if (name == null) {
8838 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
8839 }
8840 else if (name.equals(StringPool.BLANK)) {
8841 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
8842 }
8843 else {
8844 bindName = true;
8845
8846 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
8847 }
8848
8849 conjunctionable = true;
8850
8851 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
8852 if (conjunctionable) {
8853 query.append(WHERE_AND);
8854 }
8855
8856 query.append(StringPool.OPEN_PARENTHESIS);
8857
8858 for (int i = 0; i < vocabularyIds.length; i++) {
8859 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
8860
8861 if ((i + 1) < vocabularyIds.length) {
8862 query.append(WHERE_OR);
8863 }
8864 }
8865
8866 query.append(StringPool.CLOSE_PARENTHESIS);
8867
8868 conjunctionable = true;
8869 }
8870
8871 String sql = query.toString();
8872
8873 Session session = null;
8874
8875 try {
8876 session = openSession();
8877
8878 Query q = session.createQuery(sql);
8879
8880 QueryPos qPos = QueryPos.getInstance(q);
8881
8882 qPos.add(groupId);
8883
8884 if (bindName) {
8885 qPos.add(name);
8886 }
8887
8888 if (vocabularyIds != null) {
8889 qPos.add(vocabularyIds);
8890 }
8891
8892 count = (Long)q.uniqueResult();
8893
8894 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
8895 finderArgs, count);
8896 }
8897 catch (Exception e) {
8898 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
8899 finderArgs);
8900
8901 throw processException(e);
8902 }
8903 finally {
8904 closeSession(session);
8905 }
8906 }
8907
8908 return count.intValue();
8909 }
8910
8911
8920 @Override
8921 public int filterCountByG_LikeN_V(long groupId, String name,
8922 long vocabularyId) throws SystemException {
8923 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8924 return countByG_LikeN_V(groupId, name, vocabularyId);
8925 }
8926
8927 StringBundler query = new StringBundler(4);
8928
8929 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
8930
8931 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8932
8933 boolean bindName = false;
8934
8935 if (name == null) {
8936 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8937 }
8938 else if (name.equals(StringPool.BLANK)) {
8939 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8940 }
8941 else {
8942 bindName = true;
8943
8944 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8945 }
8946
8947 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8948
8949 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8950 AssetCategory.class.getName(),
8951 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8952
8953 Session session = null;
8954
8955 try {
8956 session = openSession();
8957
8958 SQLQuery q = session.createSQLQuery(sql);
8959
8960 q.addScalar(COUNT_COLUMN_NAME,
8961 com.liferay.portal.kernel.dao.orm.Type.LONG);
8962
8963 QueryPos qPos = QueryPos.getInstance(q);
8964
8965 qPos.add(groupId);
8966
8967 if (bindName) {
8968 qPos.add(name.toLowerCase());
8969 }
8970
8971 qPos.add(vocabularyId);
8972
8973 Long count = (Long)q.uniqueResult();
8974
8975 return count.intValue();
8976 }
8977 catch (Exception e) {
8978 throw processException(e);
8979 }
8980 finally {
8981 closeSession(session);
8982 }
8983 }
8984
8985
8994 @Override
8995 public int filterCountByG_LikeN_V(long groupId, String name,
8996 long[] vocabularyIds) throws SystemException {
8997 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8998 return countByG_LikeN_V(groupId, name, vocabularyIds);
8999 }
9000
9001 StringBundler query = new StringBundler();
9002
9003 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
9004
9005 boolean conjunctionable = false;
9006
9007 if (conjunctionable) {
9008 query.append(WHERE_AND);
9009 }
9010
9011 query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_5);
9012
9013 conjunctionable = true;
9014
9015 if (conjunctionable) {
9016 query.append(WHERE_AND);
9017 }
9018
9019 boolean bindName = false;
9020
9021 if (name == null) {
9022 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_4);
9023 }
9024 else if (name.equals(StringPool.BLANK)) {
9025 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_6);
9026 }
9027 else {
9028 bindName = true;
9029
9030 query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_5);
9031 }
9032
9033 conjunctionable = true;
9034
9035 if ((vocabularyIds == null) || (vocabularyIds.length > 0)) {
9036 if (conjunctionable) {
9037 query.append(WHERE_AND);
9038 }
9039
9040 query.append(StringPool.OPEN_PARENTHESIS);
9041
9042 for (int i = 0; i < vocabularyIds.length; i++) {
9043 query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5);
9044
9045 if ((i + 1) < vocabularyIds.length) {
9046 query.append(WHERE_OR);
9047 }
9048 }
9049
9050 query.append(StringPool.CLOSE_PARENTHESIS);
9051
9052 conjunctionable = true;
9053 }
9054
9055 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9056 AssetCategory.class.getName(),
9057 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9058
9059 Session session = null;
9060
9061 try {
9062 session = openSession();
9063
9064 SQLQuery q = session.createSQLQuery(sql);
9065
9066 q.addScalar(COUNT_COLUMN_NAME,
9067 com.liferay.portal.kernel.dao.orm.Type.LONG);
9068
9069 QueryPos qPos = QueryPos.getInstance(q);
9070
9071 qPos.add(groupId);
9072
9073 if (bindName) {
9074 qPos.add(name);
9075 }
9076
9077 if (vocabularyIds != null) {
9078 qPos.add(vocabularyIds);
9079 }
9080
9081 Long count = (Long)q.uniqueResult();
9082
9083 return count.intValue();
9084 }
9085 catch (Exception e) {
9086 throw processException(e);
9087 }
9088 finally {
9089 closeSession(session);
9090 }
9091 }
9092
9093 private static final String _FINDER_COLUMN_G_LIKEN_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
9094 private static final String _FINDER_COLUMN_G_LIKEN_V_GROUPID_5 = "(" +
9095 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2) + ")";
9096 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_1 = "assetCategory.name LIKE NULL AND ";
9097 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_2 = "lower(assetCategory.name) LIKE ? AND ";
9098 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name LIKE '') AND ";
9099 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_4 = "(" +
9100 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_NAME_1) + ")";
9101 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_5 = "(" +
9102 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_NAME_2) + ")";
9103 private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_6 = "(" +
9104 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_NAME_3) + ")";
9105 private static final String _FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
9106 private static final String _FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_5 = "(" +
9107 removeConjunction(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2) + ")";
9108 public static final FinderPath FINDER_PATH_FETCH_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9109 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
9110 AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByP_N_V",
9111 new String[] {
9112 Long.class.getName(), String.class.getName(),
9113 Long.class.getName()
9114 },
9115 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
9116 AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
9117 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
9118 public static final FinderPath FINDER_PATH_COUNT_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9119 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
9120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N_V",
9121 new String[] {
9122 Long.class.getName(), String.class.getName(),
9123 Long.class.getName()
9124 });
9125
9126
9136 @Override
9137 public AssetCategory findByP_N_V(long parentCategoryId, String name,
9138 long vocabularyId) throws NoSuchCategoryException, SystemException {
9139 AssetCategory assetCategory = fetchByP_N_V(parentCategoryId, name,
9140 vocabularyId);
9141
9142 if (assetCategory == null) {
9143 StringBundler msg = new StringBundler(8);
9144
9145 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9146
9147 msg.append("parentCategoryId=");
9148 msg.append(parentCategoryId);
9149
9150 msg.append(", name=");
9151 msg.append(name);
9152
9153 msg.append(", vocabularyId=");
9154 msg.append(vocabularyId);
9155
9156 msg.append(StringPool.CLOSE_CURLY_BRACE);
9157
9158 if (_log.isWarnEnabled()) {
9159 _log.warn(msg.toString());
9160 }
9161
9162 throw new NoSuchCategoryException(msg.toString());
9163 }
9164
9165 return assetCategory;
9166 }
9167
9168
9177 @Override
9178 public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
9179 long vocabularyId) throws SystemException {
9180 return fetchByP_N_V(parentCategoryId, name, vocabularyId, true);
9181 }
9182
9183
9193 @Override
9194 public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
9195 long vocabularyId, boolean retrieveFromCache) throws SystemException {
9196 Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
9197
9198 Object result = null;
9199
9200 if (retrieveFromCache) {
9201 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_N_V,
9202 finderArgs, this);
9203 }
9204
9205 if (result instanceof AssetCategory) {
9206 AssetCategory assetCategory = (AssetCategory)result;
9207
9208 if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
9209 !Validator.equals(name, assetCategory.getName()) ||
9210 (vocabularyId != assetCategory.getVocabularyId())) {
9211 result = null;
9212 }
9213 }
9214
9215 if (result == null) {
9216 StringBundler query = new StringBundler(5);
9217
9218 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
9219
9220 query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
9221
9222 boolean bindName = false;
9223
9224 if (name == null) {
9225 query.append(_FINDER_COLUMN_P_N_V_NAME_1);
9226 }
9227 else if (name.equals(StringPool.BLANK)) {
9228 query.append(_FINDER_COLUMN_P_N_V_NAME_3);
9229 }
9230 else {
9231 bindName = true;
9232
9233 query.append(_FINDER_COLUMN_P_N_V_NAME_2);
9234 }
9235
9236 query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
9237
9238 String sql = query.toString();
9239
9240 Session session = null;
9241
9242 try {
9243 session = openSession();
9244
9245 Query q = session.createQuery(sql);
9246
9247 QueryPos qPos = QueryPos.getInstance(q);
9248
9249 qPos.add(parentCategoryId);
9250
9251 if (bindName) {
9252 qPos.add(name);
9253 }
9254
9255 qPos.add(vocabularyId);
9256
9257 List<AssetCategory> list = q.list();
9258
9259 if (list.isEmpty()) {
9260 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
9261 finderArgs, list);
9262 }
9263 else {
9264 AssetCategory assetCategory = list.get(0);
9265
9266 result = assetCategory;
9267
9268 cacheResult(assetCategory);
9269
9270 if ((assetCategory.getParentCategoryId() != parentCategoryId) ||
9271 (assetCategory.getName() == null) ||
9272 !assetCategory.getName().equals(name) ||
9273 (assetCategory.getVocabularyId() != vocabularyId)) {
9274 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
9275 finderArgs, assetCategory);
9276 }
9277 }
9278 }
9279 catch (Exception e) {
9280 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V,
9281 finderArgs);
9282
9283 throw processException(e);
9284 }
9285 finally {
9286 closeSession(session);
9287 }
9288 }
9289
9290 if (result instanceof List<?>) {
9291 return null;
9292 }
9293 else {
9294 return (AssetCategory)result;
9295 }
9296 }
9297
9298
9307 @Override
9308 public AssetCategory removeByP_N_V(long parentCategoryId, String name,
9309 long vocabularyId) throws NoSuchCategoryException, SystemException {
9310 AssetCategory assetCategory = findByP_N_V(parentCategoryId, name,
9311 vocabularyId);
9312
9313 return remove(assetCategory);
9314 }
9315
9316
9325 @Override
9326 public int countByP_N_V(long parentCategoryId, String name,
9327 long vocabularyId) throws SystemException {
9328 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N_V;
9329
9330 Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
9331
9332 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9333 this);
9334
9335 if (count == null) {
9336 StringBundler query = new StringBundler(4);
9337
9338 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
9339
9340 query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
9341
9342 boolean bindName = false;
9343
9344 if (name == null) {
9345 query.append(_FINDER_COLUMN_P_N_V_NAME_1);
9346 }
9347 else if (name.equals(StringPool.BLANK)) {
9348 query.append(_FINDER_COLUMN_P_N_V_NAME_3);
9349 }
9350 else {
9351 bindName = true;
9352
9353 query.append(_FINDER_COLUMN_P_N_V_NAME_2);
9354 }
9355
9356 query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
9357
9358 String sql = query.toString();
9359
9360 Session session = null;
9361
9362 try {
9363 session = openSession();
9364
9365 Query q = session.createQuery(sql);
9366
9367 QueryPos qPos = QueryPos.getInstance(q);
9368
9369 qPos.add(parentCategoryId);
9370
9371 if (bindName) {
9372 qPos.add(name);
9373 }
9374
9375 qPos.add(vocabularyId);
9376
9377 count = (Long)q.uniqueResult();
9378
9379 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9380 }
9381 catch (Exception e) {
9382 FinderCacheUtil.removeResult(finderPath, finderArgs);
9383
9384 throw processException(e);
9385 }
9386 finally {
9387 closeSession(session);
9388 }
9389 }
9390
9391 return count.intValue();
9392 }
9393
9394 private static final String _FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
9395 private static final String _FINDER_COLUMN_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
9396 private static final String _FINDER_COLUMN_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
9397 private static final String _FINDER_COLUMN_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
9398 private static final String _FINDER_COLUMN_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
9399 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9400 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
9401 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
9402 "findByG_P_N_V",
9403 new String[] {
9404 Long.class.getName(), Long.class.getName(),
9405 String.class.getName(), Long.class.getName(),
9406
9407 Integer.class.getName(), Integer.class.getName(),
9408 OrderByComparator.class.getName()
9409 });
9410 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V =
9411 new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9412 AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
9413 AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
9414 "findByG_P_N_V",
9415 new String[] {
9416 Long.class.getName(), Long.class.getName(),
9417 String.class.getName(), Long.class.getName()
9418 },
9419 AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
9420 AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
9421 AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
9422 AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
9423 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9424 AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
9425 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N_V",
9426 new String[] {
9427 Long.class.getName(), Long.class.getName(),
9428 String.class.getName(), Long.class.getName()
9429 });
9430
9431
9441 @Override
9442 public List<AssetCategory> findByG_P_N_V(long groupId,
9443 long parentCategoryId, String name, long vocabularyId)
9444 throws SystemException {
9445 return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
9446 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9447 }
9448
9449
9465 @Override
9466 public List<AssetCategory> findByG_P_N_V(long groupId,
9467 long parentCategoryId, String name, long vocabularyId, int start,
9468 int end) throws SystemException {
9469 return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
9470 start, end, null);
9471 }
9472
9473
9490 @Override
9491 public List<AssetCategory> findByG_P_N_V(long groupId,
9492 long parentCategoryId, String name, long vocabularyId, int start,
9493 int end, OrderByComparator orderByComparator) throws SystemException {
9494 boolean pagination = true;
9495 FinderPath finderPath = null;
9496 Object[] finderArgs = null;
9497
9498 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9499 (orderByComparator == null)) {
9500 pagination = false;
9501 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V;
9502 finderArgs = new Object[] {
9503 groupId, parentCategoryId, name, vocabularyId
9504 };
9505 }
9506 else {
9507 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V;
9508 finderArgs = new Object[] {
9509 groupId, parentCategoryId, name, vocabularyId,
9510
9511 start, end, orderByComparator
9512 };
9513 }
9514
9515 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
9516 finderArgs, this);
9517
9518 if ((list != null) && !list.isEmpty()) {
9519 for (AssetCategory assetCategory : list) {
9520 if ((groupId != assetCategory.getGroupId()) ||
9521 (parentCategoryId != assetCategory.getParentCategoryId()) ||
9522 !Validator.equals(name, assetCategory.getName()) ||
9523 (vocabularyId != assetCategory.getVocabularyId())) {
9524 list = null;
9525
9526 break;
9527 }
9528 }
9529 }
9530
9531 if (list == null) {
9532 StringBundler query = null;
9533
9534 if (orderByComparator != null) {
9535 query = new StringBundler(6 +
9536 (orderByComparator.getOrderByFields().length * 3));
9537 }
9538 else {
9539 query = new StringBundler(6);
9540 }
9541
9542 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
9543
9544 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
9545
9546 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
9547
9548 boolean bindName = false;
9549
9550 if (name == null) {
9551 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9552 }
9553 else if (name.equals(StringPool.BLANK)) {
9554 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9555 }
9556 else {
9557 bindName = true;
9558
9559 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9560 }
9561
9562 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9563
9564 if (orderByComparator != null) {
9565 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9566 orderByComparator);
9567 }
9568 else
9569 if (pagination) {
9570 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
9571 }
9572
9573 String sql = query.toString();
9574
9575 Session session = null;
9576
9577 try {
9578 session = openSession();
9579
9580 Query q = session.createQuery(sql);
9581
9582 QueryPos qPos = QueryPos.getInstance(q);
9583
9584 qPos.add(groupId);
9585
9586 qPos.add(parentCategoryId);
9587
9588 if (bindName) {
9589 qPos.add(name);
9590 }
9591
9592 qPos.add(vocabularyId);
9593
9594 if (!pagination) {
9595 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
9596 start, end, false);
9597
9598 Collections.sort(list);
9599
9600 list = new UnmodifiableList<AssetCategory>(list);
9601 }
9602 else {
9603 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
9604 start, end);
9605 }
9606
9607 cacheResult(list);
9608
9609 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9610 }
9611 catch (Exception e) {
9612 FinderCacheUtil.removeResult(finderPath, finderArgs);
9613
9614 throw processException(e);
9615 }
9616 finally {
9617 closeSession(session);
9618 }
9619 }
9620
9621 return list;
9622 }
9623
9624
9636 @Override
9637 public AssetCategory findByG_P_N_V_First(long groupId,
9638 long parentCategoryId, String name, long vocabularyId,
9639 OrderByComparator orderByComparator)
9640 throws NoSuchCategoryException, SystemException {
9641 AssetCategory assetCategory = fetchByG_P_N_V_First(groupId,
9642 parentCategoryId, name, vocabularyId, orderByComparator);
9643
9644 if (assetCategory != null) {
9645 return assetCategory;
9646 }
9647
9648 StringBundler msg = new StringBundler(10);
9649
9650 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9651
9652 msg.append("groupId=");
9653 msg.append(groupId);
9654
9655 msg.append(", parentCategoryId=");
9656 msg.append(parentCategoryId);
9657
9658 msg.append(", name=");
9659 msg.append(name);
9660
9661 msg.append(", vocabularyId=");
9662 msg.append(vocabularyId);
9663
9664 msg.append(StringPool.CLOSE_CURLY_BRACE);
9665
9666 throw new NoSuchCategoryException(msg.toString());
9667 }
9668
9669
9680 @Override
9681 public AssetCategory fetchByG_P_N_V_First(long groupId,
9682 long parentCategoryId, String name, long vocabularyId,
9683 OrderByComparator orderByComparator) throws SystemException {
9684 List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
9685 name, vocabularyId, 0, 1, orderByComparator);
9686
9687 if (!list.isEmpty()) {
9688 return list.get(0);
9689 }
9690
9691 return null;
9692 }
9693
9694
9706 @Override
9707 public AssetCategory findByG_P_N_V_Last(long groupId,
9708 long parentCategoryId, String name, long vocabularyId,
9709 OrderByComparator orderByComparator)
9710 throws NoSuchCategoryException, SystemException {
9711 AssetCategory assetCategory = fetchByG_P_N_V_Last(groupId,
9712 parentCategoryId, name, vocabularyId, orderByComparator);
9713
9714 if (assetCategory != null) {
9715 return assetCategory;
9716 }
9717
9718 StringBundler msg = new StringBundler(10);
9719
9720 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9721
9722 msg.append("groupId=");
9723 msg.append(groupId);
9724
9725 msg.append(", parentCategoryId=");
9726 msg.append(parentCategoryId);
9727
9728 msg.append(", name=");
9729 msg.append(name);
9730
9731 msg.append(", vocabularyId=");
9732 msg.append(vocabularyId);
9733
9734 msg.append(StringPool.CLOSE_CURLY_BRACE);
9735
9736 throw new NoSuchCategoryException(msg.toString());
9737 }
9738
9739
9750 @Override
9751 public AssetCategory fetchByG_P_N_V_Last(long groupId,
9752 long parentCategoryId, String name, long vocabularyId,
9753 OrderByComparator orderByComparator) throws SystemException {
9754 int count = countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
9755
9756 if (count == 0) {
9757 return null;
9758 }
9759
9760 List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
9761 name, vocabularyId, count - 1, count, orderByComparator);
9762
9763 if (!list.isEmpty()) {
9764 return list.get(0);
9765 }
9766
9767 return null;
9768 }
9769
9770
9783 @Override
9784 public AssetCategory[] findByG_P_N_V_PrevAndNext(long categoryId,
9785 long groupId, long parentCategoryId, String name, long vocabularyId,
9786 OrderByComparator orderByComparator)
9787 throws NoSuchCategoryException, SystemException {
9788 AssetCategory assetCategory = findByPrimaryKey(categoryId);
9789
9790 Session session = null;
9791
9792 try {
9793 session = openSession();
9794
9795 AssetCategory[] array = new AssetCategoryImpl[3];
9796
9797 array[0] = getByG_P_N_V_PrevAndNext(session, assetCategory,
9798 groupId, parentCategoryId, name, vocabularyId,
9799 orderByComparator, true);
9800
9801 array[1] = assetCategory;
9802
9803 array[2] = getByG_P_N_V_PrevAndNext(session, assetCategory,
9804 groupId, parentCategoryId, name, vocabularyId,
9805 orderByComparator, false);
9806
9807 return array;
9808 }
9809 catch (Exception e) {
9810 throw processException(e);
9811 }
9812 finally {
9813 closeSession(session);
9814 }
9815 }
9816
9817 protected AssetCategory getByG_P_N_V_PrevAndNext(Session session,
9818 AssetCategory assetCategory, long groupId, long parentCategoryId,
9819 String name, long vocabularyId, OrderByComparator orderByComparator,
9820 boolean previous) {
9821 StringBundler query = null;
9822
9823 if (orderByComparator != null) {
9824 query = new StringBundler(6 +
9825 (orderByComparator.getOrderByFields().length * 6));
9826 }
9827 else {
9828 query = new StringBundler(3);
9829 }
9830
9831 query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
9832
9833 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
9834
9835 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
9836
9837 boolean bindName = false;
9838
9839 if (name == null) {
9840 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9841 }
9842 else if (name.equals(StringPool.BLANK)) {
9843 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9844 }
9845 else {
9846 bindName = true;
9847
9848 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9849 }
9850
9851 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9852
9853 if (orderByComparator != null) {
9854 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9855
9856 if (orderByConditionFields.length > 0) {
9857 query.append(WHERE_AND);
9858 }
9859
9860 for (int i = 0; i < orderByConditionFields.length; i++) {
9861 query.append(_ORDER_BY_ENTITY_ALIAS);
9862 query.append(orderByConditionFields[i]);
9863
9864 if ((i + 1) < orderByConditionFields.length) {
9865 if (orderByComparator.isAscending() ^ previous) {
9866 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9867 }
9868 else {
9869 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9870 }
9871 }
9872 else {
9873 if (orderByComparator.isAscending() ^ previous) {
9874 query.append(WHERE_GREATER_THAN);
9875 }
9876 else {
9877 query.append(WHERE_LESSER_THAN);
9878 }
9879 }
9880 }
9881
9882 query.append(ORDER_BY_CLAUSE);
9883
9884 String[] orderByFields = orderByComparator.getOrderByFields();
9885
9886 for (int i = 0; i < orderByFields.length; i++) {
9887 query.append(_ORDER_BY_ENTITY_ALIAS);
9888 query.append(orderByFields[i]);
9889
9890 if ((i + 1) < orderByFields.length) {
9891 if (orderByComparator.isAscending() ^ previous) {
9892 query.append(ORDER_BY_ASC_HAS_NEXT);
9893 }
9894 else {
9895 query.append(ORDER_BY_DESC_HAS_NEXT);
9896 }
9897 }
9898 else {
9899 if (orderByComparator.isAscending() ^ previous) {
9900 query.append(ORDER_BY_ASC);
9901 }
9902 else {
9903 query.append(ORDER_BY_DESC);
9904 }
9905 }
9906 }
9907 }
9908 else {
9909 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
9910 }
9911
9912 String sql = query.toString();
9913
9914 Query q = session.createQuery(sql);
9915
9916 q.setFirstResult(0);
9917 q.setMaxResults(2);
9918
9919 QueryPos qPos = QueryPos.getInstance(q);
9920
9921 qPos.add(groupId);
9922
9923 qPos.add(parentCategoryId);
9924
9925 if (bindName) {
9926 qPos.add(name);
9927 }
9928
9929 qPos.add(vocabularyId);
9930
9931 if (orderByComparator != null) {
9932 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
9933
9934 for (Object value : values) {
9935 qPos.add(value);
9936 }
9937 }
9938
9939 List<AssetCategory> list = q.list();
9940
9941 if (list.size() == 2) {
9942 return list.get(1);
9943 }
9944 else {
9945 return null;
9946 }
9947 }
9948
9949
9959 @Override
9960 public List<AssetCategory> filterFindByG_P_N_V(long groupId,
9961 long parentCategoryId, String name, long vocabularyId)
9962 throws SystemException {
9963 return filterFindByG_P_N_V(groupId, parentCategoryId, name,
9964 vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9965 }
9966
9967
9983 @Override
9984 public List<AssetCategory> filterFindByG_P_N_V(long groupId,
9985 long parentCategoryId, String name, long vocabularyId, int start,
9986 int end) throws SystemException {
9987 return filterFindByG_P_N_V(groupId, parentCategoryId, name,
9988 vocabularyId, start, end, null);
9989 }
9990
9991
10008 @Override
10009 public List<AssetCategory> filterFindByG_P_N_V(long groupId,
10010 long parentCategoryId, String name, long vocabularyId, int start,
10011 int end, OrderByComparator orderByComparator) throws SystemException {
10012 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10013 return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
10014 start, end, orderByComparator);
10015 }
10016
10017 StringBundler query = null;
10018
10019 if (orderByComparator != null) {
10020 query = new StringBundler(6 +
10021 (orderByComparator.getOrderByFields().length * 3));
10022 }
10023 else {
10024 query = new StringBundler(6);
10025 }
10026
10027 if (getDB().isSupportsInlineDistinct()) {
10028 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
10029 }
10030 else {
10031 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
10032 }
10033
10034 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10035
10036 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10037
10038 boolean bindName = false;
10039
10040 if (name == null) {
10041 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10042 }
10043 else if (name.equals(StringPool.BLANK)) {
10044 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10045 }
10046 else {
10047 bindName = true;
10048
10049 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10050 }
10051
10052 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10053
10054 if (!getDB().isSupportsInlineDistinct()) {
10055 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
10056 }
10057
10058 if (orderByComparator != null) {
10059 if (getDB().isSupportsInlineDistinct()) {
10060 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10061 orderByComparator, true);
10062 }
10063 else {
10064 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10065 orderByComparator, true);
10066 }
10067 }
10068 else {
10069 if (getDB().isSupportsInlineDistinct()) {
10070 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
10071 }
10072 else {
10073 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
10074 }
10075 }
10076
10077 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10078 AssetCategory.class.getName(),
10079 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10080
10081 Session session = null;
10082
10083 try {
10084 session = openSession();
10085
10086 SQLQuery q = session.createSQLQuery(sql);
10087
10088 if (getDB().isSupportsInlineDistinct()) {
10089 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
10090 }
10091 else {
10092 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
10093 }
10094
10095 QueryPos qPos = QueryPos.getInstance(q);
10096
10097 qPos.add(groupId);
10098
10099 qPos.add(parentCategoryId);
10100
10101 if (bindName) {
10102 qPos.add(name);
10103 }
10104
10105 qPos.add(vocabularyId);
10106
10107 return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
10108 end);
10109 }
10110 catch (Exception e) {
10111 throw processException(e);
10112 }
10113 finally {
10114 closeSession(session);
10115 }
10116 }
10117
10118
10131 @Override
10132 public AssetCategory[] filterFindByG_P_N_V_PrevAndNext(long categoryId,
10133 long groupId, long parentCategoryId, String name, long vocabularyId,
10134 OrderByComparator orderByComparator)
10135 throws NoSuchCategoryException, SystemException {
10136 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10137 return findByG_P_N_V_PrevAndNext(categoryId, groupId,
10138 parentCategoryId, name, vocabularyId, orderByComparator);
10139 }
10140
10141 AssetCategory assetCategory = findByPrimaryKey(categoryId);
10142
10143 Session session = null;
10144
10145 try {
10146 session = openSession();
10147
10148 AssetCategory[] array = new AssetCategoryImpl[3];
10149
10150 array[0] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
10151 groupId, parentCategoryId, name, vocabularyId,
10152 orderByComparator, true);
10153
10154 array[1] = assetCategory;
10155
10156 array[2] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
10157 groupId, parentCategoryId, name, vocabularyId,
10158 orderByComparator, false);
10159
10160 return array;
10161 }
10162 catch (Exception e) {
10163 throw processException(e);
10164 }
10165 finally {
10166 closeSession(session);
10167 }
10168 }
10169
10170 protected AssetCategory filterGetByG_P_N_V_PrevAndNext(Session session,
10171 AssetCategory assetCategory, long groupId, long parentCategoryId,
10172 String name, long vocabularyId, OrderByComparator orderByComparator,
10173 boolean previous) {
10174 StringBundler query = null;
10175
10176 if (orderByComparator != null) {
10177 query = new StringBundler(6 +
10178 (orderByComparator.getOrderByFields().length * 6));
10179 }
10180 else {
10181 query = new StringBundler(3);
10182 }
10183
10184 if (getDB().isSupportsInlineDistinct()) {
10185 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
10186 }
10187 else {
10188 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
10189 }
10190
10191 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10192
10193 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10194
10195 boolean bindName = false;
10196
10197 if (name == null) {
10198 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10199 }
10200 else if (name.equals(StringPool.BLANK)) {
10201 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10202 }
10203 else {
10204 bindName = true;
10205
10206 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10207 }
10208
10209 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10210
10211 if (!getDB().isSupportsInlineDistinct()) {
10212 query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
10213 }
10214
10215 if (orderByComparator != null) {
10216 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10217
10218 if (orderByConditionFields.length > 0) {
10219 query.append(WHERE_AND);
10220 }
10221
10222 for (int i = 0; i < orderByConditionFields.length; i++) {
10223 if (getDB().isSupportsInlineDistinct()) {
10224 query.append(_ORDER_BY_ENTITY_ALIAS);
10225 }
10226 else {
10227 query.append(_ORDER_BY_ENTITY_TABLE);
10228 }
10229
10230 query.append(orderByConditionFields[i]);
10231
10232 if ((i + 1) < orderByConditionFields.length) {
10233 if (orderByComparator.isAscending() ^ previous) {
10234 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10235 }
10236 else {
10237 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10238 }
10239 }
10240 else {
10241 if (orderByComparator.isAscending() ^ previous) {
10242 query.append(WHERE_GREATER_THAN);
10243 }
10244 else {
10245 query.append(WHERE_LESSER_THAN);
10246 }
10247 }
10248 }
10249
10250 query.append(ORDER_BY_CLAUSE);
10251
10252 String[] orderByFields = orderByComparator.getOrderByFields();
10253
10254 for (int i = 0; i < orderByFields.length; i++) {
10255 if (getDB().isSupportsInlineDistinct()) {
10256 query.append(_ORDER_BY_ENTITY_ALIAS);
10257 }
10258 else {
10259 query.append(_ORDER_BY_ENTITY_TABLE);
10260 }
10261
10262 query.append(orderByFields[i]);
10263
10264 if ((i + 1) < orderByFields.length) {
10265 if (orderByComparator.isAscending() ^ previous) {
10266 query.append(ORDER_BY_ASC_HAS_NEXT);
10267 }
10268 else {
10269 query.append(ORDER_BY_DESC_HAS_NEXT);
10270 }
10271 }
10272 else {
10273 if (orderByComparator.isAscending() ^ previous) {
10274 query.append(ORDER_BY_ASC);
10275 }
10276 else {
10277 query.append(ORDER_BY_DESC);
10278 }
10279 }
10280 }
10281 }
10282 else {
10283 if (getDB().isSupportsInlineDistinct()) {
10284 query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
10285 }
10286 else {
10287 query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
10288 }
10289 }
10290
10291 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10292 AssetCategory.class.getName(),
10293 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10294
10295 SQLQuery q = session.createSQLQuery(sql);
10296
10297 q.setFirstResult(0);
10298 q.setMaxResults(2);
10299
10300 if (getDB().isSupportsInlineDistinct()) {
10301 q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
10302 }
10303 else {
10304 q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
10305 }
10306
10307 QueryPos qPos = QueryPos.getInstance(q);
10308
10309 qPos.add(groupId);
10310
10311 qPos.add(parentCategoryId);
10312
10313 if (bindName) {
10314 qPos.add(name);
10315 }
10316
10317 qPos.add(vocabularyId);
10318
10319 if (orderByComparator != null) {
10320 Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
10321
10322 for (Object value : values) {
10323 qPos.add(value);
10324 }
10325 }
10326
10327 List<AssetCategory> list = q.list();
10328
10329 if (list.size() == 2) {
10330 return list.get(1);
10331 }
10332 else {
10333 return null;
10334 }
10335 }
10336
10337
10346 @Override
10347 public void removeByG_P_N_V(long groupId, long parentCategoryId,
10348 String name, long vocabularyId) throws SystemException {
10349 for (AssetCategory assetCategory : findByG_P_N_V(groupId,
10350 parentCategoryId, name, vocabularyId, QueryUtil.ALL_POS,
10351 QueryUtil.ALL_POS, null)) {
10352 remove(assetCategory);
10353 }
10354 }
10355
10356
10366 @Override
10367 public int countByG_P_N_V(long groupId, long parentCategoryId, String name,
10368 long vocabularyId) throws SystemException {
10369 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N_V;
10370
10371 Object[] finderArgs = new Object[] {
10372 groupId, parentCategoryId, name, vocabularyId
10373 };
10374
10375 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10376 this);
10377
10378 if (count == null) {
10379 StringBundler query = new StringBundler(5);
10380
10381 query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
10382
10383 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10384
10385 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10386
10387 boolean bindName = false;
10388
10389 if (name == null) {
10390 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10391 }
10392 else if (name.equals(StringPool.BLANK)) {
10393 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10394 }
10395 else {
10396 bindName = true;
10397
10398 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10399 }
10400
10401 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10402
10403 String sql = query.toString();
10404
10405 Session session = null;
10406
10407 try {
10408 session = openSession();
10409
10410 Query q = session.createQuery(sql);
10411
10412 QueryPos qPos = QueryPos.getInstance(q);
10413
10414 qPos.add(groupId);
10415
10416 qPos.add(parentCategoryId);
10417
10418 if (bindName) {
10419 qPos.add(name);
10420 }
10421
10422 qPos.add(vocabularyId);
10423
10424 count = (Long)q.uniqueResult();
10425
10426 FinderCacheUtil.putResult(finderPath, finderArgs, count);
10427 }
10428 catch (Exception e) {
10429 FinderCacheUtil.removeResult(finderPath, finderArgs);
10430
10431 throw processException(e);
10432 }
10433 finally {
10434 closeSession(session);
10435 }
10436 }
10437
10438 return count.intValue();
10439 }
10440
10441
10451 @Override
10452 public int filterCountByG_P_N_V(long groupId, long parentCategoryId,
10453 String name, long vocabularyId) throws SystemException {
10454 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10455 return countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
10456 }
10457
10458 StringBundler query = new StringBundler(5);
10459
10460 query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
10461
10462 query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10463
10464 query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10465
10466 boolean bindName = false;
10467
10468 if (name == null) {
10469 query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10470 }
10471 else if (name.equals(StringPool.BLANK)) {
10472 query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10473 }
10474 else {
10475 bindName = true;
10476
10477 query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10478 }
10479
10480 query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10481
10482 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10483 AssetCategory.class.getName(),
10484 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10485
10486 Session session = null;
10487
10488 try {
10489 session = openSession();
10490
10491 SQLQuery q = session.createSQLQuery(sql);
10492
10493 q.addScalar(COUNT_COLUMN_NAME,
10494 com.liferay.portal.kernel.dao.orm.Type.LONG);
10495
10496 QueryPos qPos = QueryPos.getInstance(q);
10497
10498 qPos.add(groupId);
10499
10500 qPos.add(parentCategoryId);
10501
10502 if (bindName) {
10503 qPos.add(name);
10504 }
10505
10506 qPos.add(vocabularyId);
10507
10508 Long count = (Long)q.uniqueResult();
10509
10510 return count.intValue();
10511 }
10512 catch (Exception e) {
10513 throw processException(e);
10514 }
10515 finally {
10516 closeSession(session);
10517 }
10518 }
10519
10520 private static final String _FINDER_COLUMN_G_P_N_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
10521 private static final String _FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
10522 private static final String _FINDER_COLUMN_G_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
10523 private static final String _FINDER_COLUMN_G_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
10524 private static final String _FINDER_COLUMN_G_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
10525 private static final String _FINDER_COLUMN_G_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
10526
10527 public AssetCategoryPersistenceImpl() {
10528 setModelClass(AssetCategory.class);
10529 }
10530
10531
10536 @Override
10537 public void cacheResult(AssetCategory assetCategory) {
10538 EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10539 AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
10540 assetCategory);
10541
10542 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
10543 new Object[] { assetCategory.getUuid(), assetCategory.getGroupId() },
10544 assetCategory);
10545
10546 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
10547 new Object[] {
10548 assetCategory.getParentCategoryId(), assetCategory.getName(),
10549 assetCategory.getVocabularyId()
10550 }, assetCategory);
10551
10552 assetCategory.resetOriginalValues();
10553 }
10554
10555
10560 @Override
10561 public void cacheResult(List<AssetCategory> assetCategories) {
10562 for (AssetCategory assetCategory : assetCategories) {
10563 if (EntityCacheUtil.getResult(
10564 AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10565 AssetCategoryImpl.class, assetCategory.getPrimaryKey()) == null) {
10566 cacheResult(assetCategory);
10567 }
10568 else {
10569 assetCategory.resetOriginalValues();
10570 }
10571 }
10572 }
10573
10574
10581 @Override
10582 public void clearCache() {
10583 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
10584 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
10585 }
10586
10587 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
10588
10589 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
10590 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10591 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10592 }
10593
10594
10601 @Override
10602 public void clearCache(AssetCategory assetCategory) {
10603 EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10604 AssetCategoryImpl.class, assetCategory.getPrimaryKey());
10605
10606 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10607 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10608
10609 clearUniqueFindersCache(assetCategory);
10610 }
10611
10612 @Override
10613 public void clearCache(List<AssetCategory> assetCategories) {
10614 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10615 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10616
10617 for (AssetCategory assetCategory : assetCategories) {
10618 EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10619 AssetCategoryImpl.class, assetCategory.getPrimaryKey());
10620
10621 clearUniqueFindersCache(assetCategory);
10622 }
10623 }
10624
10625 protected void cacheUniqueFindersCache(AssetCategory assetCategory) {
10626 if (assetCategory.isNew()) {
10627 Object[] args = new Object[] {
10628 assetCategory.getUuid(), assetCategory.getGroupId()
10629 };
10630
10631 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
10632 Long.valueOf(1));
10633 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
10634 assetCategory);
10635
10636 args = new Object[] {
10637 assetCategory.getParentCategoryId(), assetCategory.getName(),
10638 assetCategory.getVocabularyId()
10639 };
10640
10641 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
10642 Long.valueOf(1));
10643 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
10644 assetCategory);
10645 }
10646 else {
10647 AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
10648
10649 if ((assetCategoryModelImpl.getColumnBitmask() &
10650 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
10651 Object[] args = new Object[] {
10652 assetCategory.getUuid(), assetCategory.getGroupId()
10653 };
10654
10655 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
10656 Long.valueOf(1));
10657 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
10658 assetCategory);
10659 }
10660
10661 if ((assetCategoryModelImpl.getColumnBitmask() &
10662 FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
10663 Object[] args = new Object[] {
10664 assetCategory.getParentCategoryId(),
10665 assetCategory.getName(), assetCategory.getVocabularyId()
10666 };
10667
10668 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
10669 Long.valueOf(1));
10670 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
10671 assetCategory);
10672 }
10673 }
10674 }
10675
10676 protected void clearUniqueFindersCache(AssetCategory assetCategory) {
10677 AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
10678
10679 Object[] args = new Object[] {
10680 assetCategory.getUuid(), assetCategory.getGroupId()
10681 };
10682
10683 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
10684 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
10685
10686 if ((assetCategoryModelImpl.getColumnBitmask() &
10687 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
10688 args = new Object[] {
10689 assetCategoryModelImpl.getOriginalUuid(),
10690 assetCategoryModelImpl.getOriginalGroupId()
10691 };
10692
10693 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
10694 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
10695 }
10696
10697 args = new Object[] {
10698 assetCategory.getParentCategoryId(), assetCategory.getName(),
10699 assetCategory.getVocabularyId()
10700 };
10701
10702 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
10703 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
10704
10705 if ((assetCategoryModelImpl.getColumnBitmask() &
10706 FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
10707 args = new Object[] {
10708 assetCategoryModelImpl.getOriginalParentCategoryId(),
10709 assetCategoryModelImpl.getOriginalName(),
10710 assetCategoryModelImpl.getOriginalVocabularyId()
10711 };
10712
10713 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
10714 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
10715 }
10716 }
10717
10718
10724 @Override
10725 public AssetCategory create(long categoryId) {
10726 AssetCategory assetCategory = new AssetCategoryImpl();
10727
10728 assetCategory.setNew(true);
10729 assetCategory.setPrimaryKey(categoryId);
10730
10731 String uuid = PortalUUIDUtil.generate();
10732
10733 assetCategory.setUuid(uuid);
10734
10735 return assetCategory;
10736 }
10737
10738
10746 @Override
10747 public AssetCategory remove(long categoryId)
10748 throws NoSuchCategoryException, SystemException {
10749 return remove((Serializable)categoryId);
10750 }
10751
10752
10760 @Override
10761 public AssetCategory remove(Serializable primaryKey)
10762 throws NoSuchCategoryException, SystemException {
10763 Session session = null;
10764
10765 try {
10766 session = openSession();
10767
10768 AssetCategory assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
10769 primaryKey);
10770
10771 if (assetCategory == null) {
10772 if (_log.isWarnEnabled()) {
10773 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
10774 }
10775
10776 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
10777 primaryKey);
10778 }
10779
10780 return remove(assetCategory);
10781 }
10782 catch (NoSuchCategoryException nsee) {
10783 throw nsee;
10784 }
10785 catch (Exception e) {
10786 throw processException(e);
10787 }
10788 finally {
10789 closeSession(session);
10790 }
10791 }
10792
10793 @Override
10794 protected AssetCategory removeImpl(AssetCategory assetCategory)
10795 throws SystemException {
10796 assetCategory = toUnwrappedModel(assetCategory);
10797
10798 assetCategoryToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(assetCategory.getPrimaryKey());
10799
10800 Session session = null;
10801
10802 try {
10803 session = openSession();
10804
10805 if (rebuildTreeEnabled) {
10806 session.flush();
10807
10808 shrinkTree(assetCategory);
10809
10810 clearCache();
10811
10812 session.clear();
10813 }
10814
10815 if (!session.contains(assetCategory)) {
10816 assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
10817 assetCategory.getPrimaryKeyObj());
10818 }
10819
10820 if (assetCategory != null) {
10821 session.delete(assetCategory);
10822 }
10823 }
10824 catch (Exception e) {
10825 throw processException(e);
10826 }
10827 finally {
10828 closeSession(session);
10829 }
10830
10831 if (assetCategory != null) {
10832 clearCache(assetCategory);
10833 }
10834
10835 return assetCategory;
10836 }
10837
10838 @Override
10839 public AssetCategory updateImpl(
10840 com.liferay.portlet.asset.model.AssetCategory assetCategory)
10841 throws SystemException {
10842 assetCategory = toUnwrappedModel(assetCategory);
10843
10844 boolean isNew = assetCategory.isNew();
10845
10846 AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
10847
10848 if (Validator.isNull(assetCategory.getUuid())) {
10849 String uuid = PortalUUIDUtil.generate();
10850
10851 assetCategory.setUuid(uuid);
10852 }
10853
10854 Session session = null;
10855
10856 try {
10857 session = openSession();
10858
10859 if (rebuildTreeEnabled) {
10860 session.flush();
10861
10862 if (isNew) {
10863 expandTree(assetCategory, null);
10864 }
10865 else {
10866 if (assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) {
10867 List<Long> childrenCategoryIds = getChildrenTreeCategoryIds(assetCategory);
10868
10869 shrinkTree(assetCategory);
10870
10871 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
10872 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
10873 }
10874
10875 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
10876
10877 expandTree(assetCategory, childrenCategoryIds);
10878 }
10879 }
10880
10881 clearCache();
10882
10883 session.clear();
10884 }
10885
10886 if (assetCategory.isNew()) {
10887 session.save(assetCategory);
10888
10889 assetCategory.setNew(false);
10890 }
10891 else {
10892 session.merge(assetCategory);
10893 }
10894 }
10895 catch (Exception e) {
10896 throw processException(e);
10897 }
10898 finally {
10899 closeSession(session);
10900 }
10901
10902 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10903
10904 if (isNew || !AssetCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
10905 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10906 }
10907
10908 else {
10909 if ((assetCategoryModelImpl.getColumnBitmask() &
10910 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
10911 Object[] args = new Object[] {
10912 assetCategoryModelImpl.getOriginalUuid()
10913 };
10914
10915 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
10916 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
10917 args);
10918
10919 args = new Object[] { assetCategoryModelImpl.getUuid() };
10920
10921 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
10922 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
10923 args);
10924 }
10925
10926 if ((assetCategoryModelImpl.getColumnBitmask() &
10927 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
10928 Object[] args = new Object[] {
10929 assetCategoryModelImpl.getOriginalUuid(),
10930 assetCategoryModelImpl.getOriginalCompanyId()
10931 };
10932
10933 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
10934 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
10935 args);
10936
10937 args = new Object[] {
10938 assetCategoryModelImpl.getUuid(),
10939 assetCategoryModelImpl.getCompanyId()
10940 };
10941
10942 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
10943 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
10944 args);
10945 }
10946
10947 if ((assetCategoryModelImpl.getColumnBitmask() &
10948 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
10949 Object[] args = new Object[] {
10950 assetCategoryModelImpl.getOriginalGroupId()
10951 };
10952
10953 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
10954 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
10955 args);
10956
10957 args = new Object[] { assetCategoryModelImpl.getGroupId() };
10958
10959 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
10960 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
10961 args);
10962 }
10963
10964 if ((assetCategoryModelImpl.getColumnBitmask() &
10965 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID.getColumnBitmask()) != 0) {
10966 Object[] args = new Object[] {
10967 assetCategoryModelImpl.getOriginalParentCategoryId()
10968 };
10969
10970 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
10971 args);
10972 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
10973 args);
10974
10975 args = new Object[] { assetCategoryModelImpl.getParentCategoryId() };
10976
10977 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
10978 args);
10979 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
10980 args);
10981 }
10982
10983 if ((assetCategoryModelImpl.getColumnBitmask() &
10984 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID.getColumnBitmask()) != 0) {
10985 Object[] args = new Object[] {
10986 assetCategoryModelImpl.getOriginalVocabularyId()
10987 };
10988
10989 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
10990 args);
10991 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
10992 args);
10993
10994 args = new Object[] { assetCategoryModelImpl.getVocabularyId() };
10995
10996 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
10997 args);
10998 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
10999 args);
11000 }
11001
11002 if ((assetCategoryModelImpl.getColumnBitmask() &
11003 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V.getColumnBitmask()) != 0) {
11004 Object[] args = new Object[] {
11005 assetCategoryModelImpl.getOriginalGroupId(),
11006 assetCategoryModelImpl.getOriginalVocabularyId()
11007 };
11008
11009 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
11010 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
11011 args);
11012
11013 args = new Object[] {
11014 assetCategoryModelImpl.getGroupId(),
11015 assetCategoryModelImpl.getVocabularyId()
11016 };
11017
11018 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
11019 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
11020 args);
11021 }
11022
11023 if ((assetCategoryModelImpl.getColumnBitmask() &
11024 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
11025 Object[] args = new Object[] {
11026 assetCategoryModelImpl.getOriginalParentCategoryId(),
11027 assetCategoryModelImpl.getOriginalName()
11028 };
11029
11030 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
11031 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
11032 args);
11033
11034 args = new Object[] {
11035 assetCategoryModelImpl.getParentCategoryId(),
11036 assetCategoryModelImpl.getName()
11037 };
11038
11039 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
11040 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
11041 args);
11042 }
11043
11044 if ((assetCategoryModelImpl.getColumnBitmask() &
11045 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V.getColumnBitmask()) != 0) {
11046 Object[] args = new Object[] {
11047 assetCategoryModelImpl.getOriginalParentCategoryId(),
11048 assetCategoryModelImpl.getOriginalVocabularyId()
11049 };
11050
11051 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
11052 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
11053 args);
11054
11055 args = new Object[] {
11056 assetCategoryModelImpl.getParentCategoryId(),
11057 assetCategoryModelImpl.getVocabularyId()
11058 };
11059
11060 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
11061 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
11062 args);
11063 }
11064
11065 if ((assetCategoryModelImpl.getColumnBitmask() &
11066 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V.getColumnBitmask()) != 0) {
11067 Object[] args = new Object[] {
11068 assetCategoryModelImpl.getOriginalName(),
11069 assetCategoryModelImpl.getOriginalVocabularyId()
11070 };
11071
11072 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
11073 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
11074 args);
11075
11076 args = new Object[] {
11077 assetCategoryModelImpl.getName(),
11078 assetCategoryModelImpl.getVocabularyId()
11079 };
11080
11081 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
11082 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
11083 args);
11084 }
11085
11086 if ((assetCategoryModelImpl.getColumnBitmask() &
11087 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V.getColumnBitmask()) != 0) {
11088 Object[] args = new Object[] {
11089 assetCategoryModelImpl.getOriginalGroupId(),
11090 assetCategoryModelImpl.getOriginalParentCategoryId(),
11091 assetCategoryModelImpl.getOriginalVocabularyId()
11092 };
11093
11094 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_V, args);
11095 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V,
11096 args);
11097
11098 args = new Object[] {
11099 assetCategoryModelImpl.getGroupId(),
11100 assetCategoryModelImpl.getParentCategoryId(),
11101 assetCategoryModelImpl.getVocabularyId()
11102 };
11103
11104 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_V, args);
11105 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V,
11106 args);
11107 }
11108
11109 if ((assetCategoryModelImpl.getColumnBitmask() &
11110 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V.getColumnBitmask()) != 0) {
11111 Object[] args = new Object[] {
11112 assetCategoryModelImpl.getOriginalGroupId(),
11113 assetCategoryModelImpl.getOriginalParentCategoryId(),
11114 assetCategoryModelImpl.getOriginalName(),
11115 assetCategoryModelImpl.getOriginalVocabularyId()
11116 };
11117
11118 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
11119 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
11120 args);
11121
11122 args = new Object[] {
11123 assetCategoryModelImpl.getGroupId(),
11124 assetCategoryModelImpl.getParentCategoryId(),
11125 assetCategoryModelImpl.getName(),
11126 assetCategoryModelImpl.getVocabularyId()
11127 };
11128
11129 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
11130 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
11131 args);
11132 }
11133 }
11134
11135 EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11136 AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
11137 assetCategory);
11138
11139 clearUniqueFindersCache(assetCategory);
11140 cacheUniqueFindersCache(assetCategory);
11141
11142 return assetCategory;
11143 }
11144
11145 protected AssetCategory toUnwrappedModel(AssetCategory assetCategory) {
11146 if (assetCategory instanceof AssetCategoryImpl) {
11147 return assetCategory;
11148 }
11149
11150 AssetCategoryImpl assetCategoryImpl = new AssetCategoryImpl();
11151
11152 assetCategoryImpl.setNew(assetCategory.isNew());
11153 assetCategoryImpl.setPrimaryKey(assetCategory.getPrimaryKey());
11154
11155 assetCategoryImpl.setUuid(assetCategory.getUuid());
11156 assetCategoryImpl.setCategoryId(assetCategory.getCategoryId());
11157 assetCategoryImpl.setGroupId(assetCategory.getGroupId());
11158 assetCategoryImpl.setCompanyId(assetCategory.getCompanyId());
11159 assetCategoryImpl.setUserId(assetCategory.getUserId());
11160 assetCategoryImpl.setUserName(assetCategory.getUserName());
11161 assetCategoryImpl.setCreateDate(assetCategory.getCreateDate());
11162 assetCategoryImpl.setModifiedDate(assetCategory.getModifiedDate());
11163 assetCategoryImpl.setParentCategoryId(assetCategory.getParentCategoryId());
11164 assetCategoryImpl.setLeftCategoryId(assetCategory.getLeftCategoryId());
11165 assetCategoryImpl.setRightCategoryId(assetCategory.getRightCategoryId());
11166 assetCategoryImpl.setName(assetCategory.getName());
11167 assetCategoryImpl.setTitle(assetCategory.getTitle());
11168 assetCategoryImpl.setDescription(assetCategory.getDescription());
11169 assetCategoryImpl.setVocabularyId(assetCategory.getVocabularyId());
11170
11171 return assetCategoryImpl;
11172 }
11173
11174
11182 @Override
11183 public AssetCategory findByPrimaryKey(Serializable primaryKey)
11184 throws NoSuchCategoryException, SystemException {
11185 AssetCategory assetCategory = fetchByPrimaryKey(primaryKey);
11186
11187 if (assetCategory == null) {
11188 if (_log.isWarnEnabled()) {
11189 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
11190 }
11191
11192 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11193 primaryKey);
11194 }
11195
11196 return assetCategory;
11197 }
11198
11199
11207 @Override
11208 public AssetCategory findByPrimaryKey(long categoryId)
11209 throws NoSuchCategoryException, SystemException {
11210 return findByPrimaryKey((Serializable)categoryId);
11211 }
11212
11213
11220 @Override
11221 public AssetCategory fetchByPrimaryKey(Serializable primaryKey)
11222 throws SystemException {
11223 AssetCategory assetCategory = (AssetCategory)EntityCacheUtil.getResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11224 AssetCategoryImpl.class, primaryKey);
11225
11226 if (assetCategory == _nullAssetCategory) {
11227 return null;
11228 }
11229
11230 if (assetCategory == null) {
11231 Session session = null;
11232
11233 try {
11234 session = openSession();
11235
11236 assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
11237 primaryKey);
11238
11239 if (assetCategory != null) {
11240 cacheResult(assetCategory);
11241 }
11242 else {
11243 EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11244 AssetCategoryImpl.class, primaryKey, _nullAssetCategory);
11245 }
11246 }
11247 catch (Exception e) {
11248 EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11249 AssetCategoryImpl.class, primaryKey);
11250
11251 throw processException(e);
11252 }
11253 finally {
11254 closeSession(session);
11255 }
11256 }
11257
11258 return assetCategory;
11259 }
11260
11261
11268 @Override
11269 public AssetCategory fetchByPrimaryKey(long categoryId)
11270 throws SystemException {
11271 return fetchByPrimaryKey((Serializable)categoryId);
11272 }
11273
11274
11280 @Override
11281 public List<AssetCategory> findAll() throws SystemException {
11282 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11283 }
11284
11285
11297 @Override
11298 public List<AssetCategory> findAll(int start, int end)
11299 throws SystemException {
11300 return findAll(start, end, null);
11301 }
11302
11303
11316 @Override
11317 public List<AssetCategory> findAll(int start, int end,
11318 OrderByComparator orderByComparator) throws SystemException {
11319 boolean pagination = true;
11320 FinderPath finderPath = null;
11321 Object[] finderArgs = null;
11322
11323 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11324 (orderByComparator == null)) {
11325 pagination = false;
11326 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
11327 finderArgs = FINDER_ARGS_EMPTY;
11328 }
11329 else {
11330 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
11331 finderArgs = new Object[] { start, end, orderByComparator };
11332 }
11333
11334 List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
11335 finderArgs, this);
11336
11337 if (list == null) {
11338 StringBundler query = null;
11339 String sql = null;
11340
11341 if (orderByComparator != null) {
11342 query = new StringBundler(2 +
11343 (orderByComparator.getOrderByFields().length * 3));
11344
11345 query.append(_SQL_SELECT_ASSETCATEGORY);
11346
11347 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11348 orderByComparator);
11349
11350 sql = query.toString();
11351 }
11352 else {
11353 sql = _SQL_SELECT_ASSETCATEGORY;
11354
11355 if (pagination) {
11356 sql = sql.concat(AssetCategoryModelImpl.ORDER_BY_JPQL);
11357 }
11358 }
11359
11360 Session session = null;
11361
11362 try {
11363 session = openSession();
11364
11365 Query q = session.createQuery(sql);
11366
11367 if (!pagination) {
11368 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
11369 start, end, false);
11370
11371 Collections.sort(list);
11372
11373 list = new UnmodifiableList<AssetCategory>(list);
11374 }
11375 else {
11376 list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
11377 start, end);
11378 }
11379
11380 cacheResult(list);
11381
11382 FinderCacheUtil.putResult(finderPath, finderArgs, list);
11383 }
11384 catch (Exception e) {
11385 FinderCacheUtil.removeResult(finderPath, finderArgs);
11386
11387 throw processException(e);
11388 }
11389 finally {
11390 closeSession(session);
11391 }
11392 }
11393
11394 return list;
11395 }
11396
11397
11402 @Override
11403 public void removeAll() throws SystemException {
11404 for (AssetCategory assetCategory : findAll()) {
11405 remove(assetCategory);
11406 }
11407 }
11408
11409
11415 @Override
11416 public int countAll() throws SystemException {
11417 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
11418 FINDER_ARGS_EMPTY, this);
11419
11420 if (count == null) {
11421 Session session = null;
11422
11423 try {
11424 session = openSession();
11425
11426 Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORY);
11427
11428 count = (Long)q.uniqueResult();
11429
11430 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
11431 FINDER_ARGS_EMPTY, count);
11432 }
11433 catch (Exception e) {
11434 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
11435 FINDER_ARGS_EMPTY);
11436
11437 throw processException(e);
11438 }
11439 finally {
11440 closeSession(session);
11441 }
11442 }
11443
11444 return count.intValue();
11445 }
11446
11447
11454 @Override
11455 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
11456 long pk) throws SystemException {
11457 return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
11458 }
11459
11460
11473 @Override
11474 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
11475 long pk, int start, int end) throws SystemException {
11476 return getAssetEntries(pk, start, end, null);
11477 }
11478
11479
11493 @Override
11494 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
11495 long pk, int start, int end, OrderByComparator orderByComparator)
11496 throws SystemException {
11497 return assetCategoryToAssetEntryTableMapper.getRightBaseModels(pk,
11498 start, end, orderByComparator);
11499 }
11500
11501
11508 @Override
11509 public int getAssetEntriesSize(long pk) throws SystemException {
11510 long[] pks = assetCategoryToAssetEntryTableMapper.getRightPrimaryKeys(pk);
11511
11512 return pks.length;
11513 }
11514
11515
11523 @Override
11524 public boolean containsAssetEntry(long pk, long assetEntryPK)
11525 throws SystemException {
11526 return assetCategoryToAssetEntryTableMapper.containsTableMapping(pk,
11527 assetEntryPK);
11528 }
11529
11530
11537 @Override
11538 public boolean containsAssetEntries(long pk) throws SystemException {
11539 if (getAssetEntriesSize(pk) > 0) {
11540 return true;
11541 }
11542 else {
11543 return false;
11544 }
11545 }
11546
11547
11554 @Override
11555 public void addAssetEntry(long pk, long assetEntryPK)
11556 throws SystemException {
11557 assetCategoryToAssetEntryTableMapper.addTableMapping(pk, assetEntryPK);
11558 }
11559
11560
11567 @Override
11568 public void addAssetEntry(long pk,
11569 com.liferay.portlet.asset.model.AssetEntry assetEntry)
11570 throws SystemException {
11571 assetCategoryToAssetEntryTableMapper.addTableMapping(pk,
11572 assetEntry.getPrimaryKey());
11573 }
11574
11575
11582 @Override
11583 public void addAssetEntries(long pk, long[] assetEntryPKs)
11584 throws SystemException {
11585 for (long assetEntryPK : assetEntryPKs) {
11586 assetCategoryToAssetEntryTableMapper.addTableMapping(pk,
11587 assetEntryPK);
11588 }
11589 }
11590
11591
11598 @Override
11599 public void addAssetEntries(long pk,
11600 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
11601 throws SystemException {
11602 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
11603 assetCategoryToAssetEntryTableMapper.addTableMapping(pk,
11604 assetEntry.getPrimaryKey());
11605 }
11606 }
11607
11608
11614 @Override
11615 public void clearAssetEntries(long pk) throws SystemException {
11616 assetCategoryToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
11617 }
11618
11619
11626 @Override
11627 public void removeAssetEntry(long pk, long assetEntryPK)
11628 throws SystemException {
11629 assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk, assetEntryPK);
11630 }
11631
11632
11639 @Override
11640 public void removeAssetEntry(long pk,
11641 com.liferay.portlet.asset.model.AssetEntry assetEntry)
11642 throws SystemException {
11643 assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11644 assetEntry.getPrimaryKey());
11645 }
11646
11647
11654 @Override
11655 public void removeAssetEntries(long pk, long[] assetEntryPKs)
11656 throws SystemException {
11657 for (long assetEntryPK : assetEntryPKs) {
11658 assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11659 assetEntryPK);
11660 }
11661 }
11662
11663
11670 @Override
11671 public void removeAssetEntries(long pk,
11672 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
11673 throws SystemException {
11674 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
11675 assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11676 assetEntry.getPrimaryKey());
11677 }
11678 }
11679
11680
11687 @Override
11688 public void setAssetEntries(long pk, long[] assetEntryPKs)
11689 throws SystemException {
11690 Set<Long> newAssetEntryPKsSet = SetUtil.fromArray(assetEntryPKs);
11691 Set<Long> oldAssetEntryPKsSet = SetUtil.fromArray(assetCategoryToAssetEntryTableMapper.getRightPrimaryKeys(
11692 pk));
11693
11694 Set<Long> removeAssetEntryPKsSet = new HashSet<Long>(oldAssetEntryPKsSet);
11695
11696 removeAssetEntryPKsSet.removeAll(newAssetEntryPKsSet);
11697
11698 for (long removeAssetEntryPK : removeAssetEntryPKsSet) {
11699 assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11700 removeAssetEntryPK);
11701 }
11702
11703 newAssetEntryPKsSet.removeAll(oldAssetEntryPKsSet);
11704
11705 for (long newAssetEntryPK : newAssetEntryPKsSet) {
11706 assetCategoryToAssetEntryTableMapper.addTableMapping(pk,
11707 newAssetEntryPK);
11708 }
11709 }
11710
11711
11718 @Override
11719 public void setAssetEntries(long pk,
11720 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
11721 throws SystemException {
11722 try {
11723 long[] assetEntryPKs = new long[assetEntries.size()];
11724
11725 for (int i = 0; i < assetEntries.size(); i++) {
11726 com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
11727
11728 assetEntryPKs[i] = assetEntry.getPrimaryKey();
11729 }
11730
11731 setAssetEntries(pk, assetEntryPKs);
11732 }
11733 catch (Exception e) {
11734 throw processException(e);
11735 }
11736 finally {
11737 FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
11738 }
11739 }
11740
11741 @Override
11742 protected Set<String> getBadColumnNames() {
11743 return _badColumnNames;
11744 }
11745
11746
11756 @Override
11757 public void rebuildTree(long groupId, boolean force)
11758 throws SystemException {
11759 if (!rebuildTreeEnabled) {
11760 return;
11761 }
11762
11763 if (force || (countOrphanTreeNodes(groupId) > 0)) {
11764 rebuildTree(groupId, 0, 1);
11765
11766 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
11767 CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
11768 }
11769
11770 EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
11771 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
11772 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11773 }
11774 }
11775
11776 @Override
11777 public void setRebuildTreeEnabled(boolean rebuildTreeEnabled) {
11778 this.rebuildTreeEnabled = rebuildTreeEnabled;
11779 }
11780
11781 protected long countOrphanTreeNodes(long groupId) throws SystemException {
11782 Session session = null;
11783
11784 try {
11785 session = openSession();
11786
11787 SQLQuery q = session.createSQLQuery(
11788 "SELECT COUNT(*) AS COUNT_VALUE FROM AssetCategory WHERE groupId = ? AND (leftCategoryId = 0 OR leftCategoryId IS NULL OR rightCategoryId = 0 OR rightCategoryId IS NULL)");
11789
11790 q.addScalar(COUNT_COLUMN_NAME,
11791 com.liferay.portal.kernel.dao.orm.Type.LONG);
11792
11793 QueryPos qPos = QueryPos.getInstance(q);
11794
11795 qPos.add(groupId);
11796
11797 return (Long)q.uniqueResult();
11798 }
11799 catch (Exception e) {
11800 throw processException(e);
11801 }
11802 finally {
11803 closeSession(session);
11804 }
11805 }
11806
11807 protected void expandNoChildrenLeftCategoryId(long groupId,
11808 long leftCategoryId, List<Long> childrenCategoryIds, long delta) {
11809 String sql = "UPDATE AssetCategory SET leftcategoryId = (leftcategoryId + ?) WHERE (groupId = ?) AND (leftcategoryId > ?) AND (categoryId NOT IN (" +
11810 StringUtil.merge(childrenCategoryIds) + "))";
11811
11812 SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11813 sql,
11814 new int[] {
11815 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
11816 java.sql.Types.BIGINT
11817 });
11818
11819 _sqlUpdate.update(new Object[] { delta, groupId, leftCategoryId });
11820 }
11821
11822 protected void expandNoChildrenRightCategoryId(long groupId,
11823 long rightCategoryId, List<Long> childrenCategoryIds, long delta) {
11824 String sql = "UPDATE AssetCategory SET rightcategoryId = (rightcategoryId + ?) WHERE (groupId = ?) AND (rightcategoryId > ?) AND (categoryId NOT IN (" +
11825 StringUtil.merge(childrenCategoryIds) + "))";
11826
11827 SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
11828 sql,
11829 new int[] {
11830 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
11831 java.sql.Types.BIGINT
11832 });
11833
11834 _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
11835 }
11836
11837 protected void expandTree(AssetCategory assetCategory,
11838 List<Long> childrenCategoryIds) throws SystemException {
11839 if (!rebuildTreeEnabled) {
11840 return;
11841 }
11842
11843 long groupId = assetCategory.getGroupId();
11844
11845 long lastRightCategoryId = getLastRightCategoryId(groupId,
11846 assetCategory.getParentCategoryId());
11847
11848 long leftCategoryId = 2;
11849 long rightCategoryId = 3;
11850
11851 if (lastRightCategoryId > 0) {
11852 leftCategoryId = lastRightCategoryId + 1;
11853
11854 long childrenDistance = assetCategory.getRightCategoryId() -
11855 assetCategory.getLeftCategoryId();
11856
11857 if (childrenDistance > 1) {
11858 rightCategoryId = leftCategoryId + childrenDistance;
11859
11860 updateChildrenTree(groupId, childrenCategoryIds,
11861 leftCategoryId - assetCategory.getLeftCategoryId());
11862
11863 expandNoChildrenLeftCategoryId(groupId, lastRightCategoryId,
11864 childrenCategoryIds, childrenDistance + 1);
11865 expandNoChildrenRightCategoryId(groupId, lastRightCategoryId,
11866 childrenCategoryIds, childrenDistance + 1);
11867 }
11868 else {
11869 rightCategoryId = lastRightCategoryId + 2;
11870
11871 expandTreeLeftCategoryId.expand(groupId, lastRightCategoryId);
11872 expandTreeRightCategoryId.expand(groupId, lastRightCategoryId);
11873 }
11874 }
11875
11876 assetCategory.setLeftCategoryId(leftCategoryId);
11877 assetCategory.setRightCategoryId(rightCategoryId);
11878 }
11879
11880 protected List<Long> getChildrenTreeCategoryIds(
11881 AssetCategory parentAssetCategory) throws SystemException {
11882 Session session = null;
11883
11884 try {
11885 session = openSession();
11886
11887 SQLQuery q = session.createSQLQuery(
11888 "SELECT categoryId FROM AssetCategory WHERE (groupId = ?) AND (leftcategoryId BETWEEN ? AND ?)");
11889
11890 q.addScalar("CategoryId",
11891 com.liferay.portal.kernel.dao.orm.Type.LONG);
11892
11893 QueryPos qPos = QueryPos.getInstance(q);
11894
11895 qPos.add(parentAssetCategory.getGroupId());
11896 qPos.add(parentAssetCategory.getLeftCategoryId() + 1);
11897 qPos.add(parentAssetCategory.getRightCategoryId());
11898
11899 return q.list();
11900 }
11901 catch (Exception e) {
11902 throw processException(e);
11903 }
11904 finally {
11905 closeSession(session);
11906 }
11907 }
11908
11909 protected long getLastRightCategoryId(long groupId, long parentCategoryId)
11910 throws SystemException {
11911 Session session = null;
11912
11913 try {
11914 session = openSession();
11915
11916 SQLQuery q = session.createSQLQuery(
11917 "SELECT rightCategoryId FROM AssetCategory WHERE (groupId = ?) AND (parentCategoryId = ?) ORDER BY rightCategoryId DESC");
11918
11919 q.addScalar("rightCategoryId",
11920 com.liferay.portal.kernel.dao.orm.Type.LONG);
11921
11922 QueryPos qPos = QueryPos.getInstance(q);
11923
11924 qPos.add(groupId);
11925 qPos.add(parentCategoryId);
11926
11927 List<Long> list = (List<Long>)QueryUtil.list(q, getDialect(), 0, 1);
11928
11929 if (list.isEmpty()) {
11930 if (parentCategoryId > 0) {
11931 session.clear();
11932
11933 AssetCategory parentAssetCategory = findByPrimaryKey(parentCategoryId);
11934
11935 return parentAssetCategory.getLeftCategoryId();
11936 }
11937
11938 return 0;
11939 }
11940 else {
11941 return list.get(0);
11942 }
11943 }
11944 catch (Exception e) {
11945 throw processException(e);
11946 }
11947 finally {
11948 closeSession(session);
11949 }
11950 }
11951
11952 protected long rebuildTree(long groupId, long parentCategoryId,
11953 long leftCategoryId) throws SystemException {
11954 if (!rebuildTreeEnabled) {
11955 return 0;
11956 }
11957
11958 List<Long> categoryIds = null;
11959
11960 Session session = null;
11961
11962 try {
11963 session = openSession();
11964
11965 SQLQuery q = session.createSQLQuery(
11966 "SELECT categoryId FROM AssetCategory WHERE groupId = ? AND parentCategoryId = ? ORDER BY categoryId ASC");
11967
11968 q.addScalar("categoryId",
11969 com.liferay.portal.kernel.dao.orm.Type.LONG);
11970
11971 QueryPos qPos = QueryPos.getInstance(q);
11972
11973 qPos.add(groupId);
11974 qPos.add(parentCategoryId);
11975
11976 categoryIds = q.list();
11977 }
11978 catch (Exception e) {
11979 throw processException(e);
11980 }
11981 finally {
11982 closeSession(session);
11983 }
11984
11985 long rightCategoryId = leftCategoryId + 1;
11986
11987 for (long categoryId : categoryIds) {
11988 rightCategoryId = rebuildTree(groupId, categoryId, rightCategoryId);
11989 }
11990
11991 if (parentCategoryId > 0) {
11992 updateTree.update(parentCategoryId, leftCategoryId, rightCategoryId);
11993 }
11994
11995 return rightCategoryId + 1;
11996 }
11997
11998 protected void shrinkTree(AssetCategory assetCategory) {
11999 if (!rebuildTreeEnabled) {
12000 return;
12001 }
12002
12003 long groupId = assetCategory.getGroupId();
12004
12005 long leftCategoryId = assetCategory.getLeftCategoryId();
12006 long rightCategoryId = assetCategory.getRightCategoryId();
12007
12008 long delta = (rightCategoryId - leftCategoryId) + 1;
12009
12010 shrinkTreeLeftCategoryId.shrink(groupId, rightCategoryId, delta);
12011 shrinkTreeRightCategoryId.shrink(groupId, rightCategoryId, delta);
12012 }
12013
12014 protected void updateChildrenTree(long groupId,
12015 List<Long> childrenCategoryIds, long delta) {
12016 String sql = "UPDATE AssetCategory SET leftcategoryId = (leftcategoryId + ?), rightcategoryId = (rightcategoryId + ?) WHERE (groupId = ?) AND (categoryId IN (" +
12017 StringUtil.merge(childrenCategoryIds) + "))";
12018
12019 SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12020 sql,
12021 new int[] {
12022 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
12023 java.sql.Types.BIGINT
12024 });
12025
12026 _sqlUpdate.update(new Object[] { delta, delta, groupId });
12027 }
12028
12029
12032 public void afterPropertiesSet() {
12033 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
12034 com.liferay.portal.util.PropsUtil.get(
12035 "value.object.listener.com.liferay.portlet.asset.model.AssetCategory")));
12036
12037 if (listenerClassNames.length > 0) {
12038 try {
12039 List<ModelListener<AssetCategory>> listenersList = new ArrayList<ModelListener<AssetCategory>>();
12040
12041 for (String listenerClassName : listenerClassNames) {
12042 listenersList.add((ModelListener<AssetCategory>)InstanceFactory.newInstance(
12043 getClassLoader(), listenerClassName));
12044 }
12045
12046 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
12047 }
12048 catch (Exception e) {
12049 _log.error(e);
12050 }
12051 }
12052
12053 assetCategoryToAssetEntryTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetCategories",
12054 "categoryId", "entryId", this, assetEntryPersistence);
12055
12056 expandTreeLeftCategoryId = new ExpandTreeLeftCategoryId();
12057 expandTreeRightCategoryId = new ExpandTreeRightCategoryId();
12058 shrinkTreeLeftCategoryId = new ShrinkTreeLeftCategoryId();
12059 shrinkTreeRightCategoryId = new ShrinkTreeRightCategoryId();
12060 updateTree = new UpdateTree();
12061 }
12062
12063 public void destroy() {
12064 EntityCacheUtil.removeCache(AssetCategoryImpl.class.getName());
12065 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
12066 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12067 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12068 }
12069
12070 @BeanReference(type = AssetEntryPersistence.class)
12071 protected AssetEntryPersistence assetEntryPersistence;
12072 protected TableMapper<AssetCategory, com.liferay.portlet.asset.model.AssetEntry> assetCategoryToAssetEntryTableMapper;
12073 protected boolean rebuildTreeEnabled = true;
12074 protected ExpandTreeLeftCategoryId expandTreeLeftCategoryId;
12075 protected ExpandTreeRightCategoryId expandTreeRightCategoryId;
12076 protected ShrinkTreeLeftCategoryId shrinkTreeLeftCategoryId;
12077 protected ShrinkTreeRightCategoryId shrinkTreeRightCategoryId;
12078 protected UpdateTree updateTree;
12079
12080 protected class ExpandTreeLeftCategoryId {
12081 protected ExpandTreeLeftCategoryId() {
12082 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12083 "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId + 2) WHERE (groupId = ?) AND (leftCategoryId > ?)",
12084 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
12085 }
12086
12087 protected void expand(long groupId, long leftCategoryId) {
12088 _sqlUpdate.update(new Object[] { groupId, leftCategoryId });
12089 }
12090
12091 private SqlUpdate _sqlUpdate;
12092 }
12093
12094 protected class ExpandTreeRightCategoryId {
12095 protected ExpandTreeRightCategoryId() {
12096 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12097 "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId + 2) WHERE (groupId = ?) AND (rightCategoryId > ?)",
12098 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
12099 }
12100
12101 protected void expand(long groupId, long rightCategoryId) {
12102 _sqlUpdate.update(new Object[] { groupId, rightCategoryId });
12103 }
12104
12105 private SqlUpdate _sqlUpdate;
12106 }
12107
12108 protected class ShrinkTreeLeftCategoryId {
12109 protected ShrinkTreeLeftCategoryId() {
12110 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12111 "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId - ?) WHERE (groupId = ?) AND (leftCategoryId > ?)",
12112 new int[] {
12113 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
12114 java.sql.Types.BIGINT
12115 });
12116 }
12117
12118 protected void shrink(long groupId, long rightCategoryId, long delta) {
12119 _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
12120 }
12121
12122 private SqlUpdate _sqlUpdate;
12123 }
12124
12125 protected class ShrinkTreeRightCategoryId {
12126 protected ShrinkTreeRightCategoryId() {
12127 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12128 "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId - ?) WHERE (groupId = ?) AND (rightCategoryId > ?)",
12129 new int[] {
12130 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
12131 java.sql.Types.BIGINT
12132 });
12133 }
12134
12135 protected void shrink(long groupId, long rightCategoryId, long delta) {
12136 _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
12137 }
12138
12139 private SqlUpdate _sqlUpdate;
12140 }
12141
12142 protected class UpdateTree {
12143 protected UpdateTree() {
12144 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12145 "UPDATE AssetCategory SET leftCategoryId = ?, rightCategoryId = ? WHERE categoryId = ?",
12146 new int[] {
12147 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
12148 java.sql.Types.BIGINT
12149 });
12150 }
12151
12152 protected void update(long categoryId, long leftCategoryId,
12153 long rightCategoryId) {
12154 _sqlUpdate.update(new Object[] {
12155 leftCategoryId, rightCategoryId, categoryId
12156 });
12157 }
12158
12159 private SqlUpdate _sqlUpdate;
12160 }
12161
12162 private static final String _SQL_SELECT_ASSETCATEGORY = "SELECT assetCategory FROM AssetCategory assetCategory";
12163 private static final String _SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT assetCategory FROM AssetCategory assetCategory WHERE ";
12164 private static final String _SQL_COUNT_ASSETCATEGORY = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory";
12165 private static final String _SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory WHERE ";
12166 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetCategory.categoryId";
12167 private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT DISTINCT {assetCategory.*} FROM AssetCategory assetCategory WHERE ";
12168 private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
12169 "SELECT {AssetCategory.*} FROM (SELECT DISTINCT assetCategory.categoryId FROM AssetCategory assetCategory WHERE ";
12170 private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
12171 ") TEMP_TABLE INNER JOIN AssetCategory ON TEMP_TABLE.categoryId = AssetCategory.categoryId";
12172 private static final String _FILTER_SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(DISTINCT assetCategory.categoryId) AS COUNT_VALUE FROM AssetCategory assetCategory WHERE ";
12173 private static final String _FILTER_ENTITY_ALIAS = "assetCategory";
12174 private static final String _FILTER_ENTITY_TABLE = "AssetCategory";
12175 private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategory.";
12176 private static final String _ORDER_BY_ENTITY_TABLE = "AssetCategory.";
12177 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategory exists with the primary key ";
12178 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategory exists with the key {";
12179 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
12180 private static Log _log = LogFactoryUtil.getLog(AssetCategoryPersistenceImpl.class);
12181 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
12182 "uuid"
12183 });
12184 private static AssetCategory _nullAssetCategory = new AssetCategoryImpl() {
12185 @Override
12186 public Object clone() {
12187 return this;
12188 }
12189
12190 @Override
12191 public CacheModel<AssetCategory> toCacheModel() {
12192 return _nullAssetCategoryCacheModel;
12193 }
12194 };
12195
12196 private static CacheModel<AssetCategory> _nullAssetCategoryCacheModel = new CacheModel<AssetCategory>() {
12197 @Override
12198 public AssetCategory toEntityModel() {
12199 return _nullAssetCategory;
12200 }
12201 };
12202 }