001
014
015 package com.liferay.portlet.asset.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.SQLQuery;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.asset.NoSuchVocabularyException;
045 import com.liferay.portlet.asset.model.AssetVocabulary;
046 import com.liferay.portlet.asset.model.impl.AssetVocabularyImpl;
047 import com.liferay.portlet.asset.model.impl.AssetVocabularyModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054 import java.util.Set;
055
056
068 public class AssetVocabularyPersistenceImpl extends BasePersistenceImpl<AssetVocabulary>
069 implements AssetVocabularyPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = AssetVocabularyImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
081 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
082 AssetVocabularyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
085 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
086 AssetVocabularyImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
089 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
092 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
093 AssetVocabularyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094 "findByUuid",
095 new String[] {
096 String.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
102 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
103 AssetVocabularyImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105 new String[] { String.class.getName() },
106 AssetVocabularyModelImpl.UUID_COLUMN_BITMASK |
107 AssetVocabularyModelImpl.NAME_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
109 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111 new String[] { String.class.getName() });
112
113
120 @Override
121 public List<AssetVocabulary> findByUuid(String uuid)
122 throws SystemException {
123 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124 }
125
126
139 @Override
140 public List<AssetVocabulary> findByUuid(String uuid, int start, int end)
141 throws SystemException {
142 return findByUuid(uuid, start, end, null);
143 }
144
145
159 @Override
160 public List<AssetVocabulary> findByUuid(String uuid, int start, int end,
161 OrderByComparator orderByComparator) throws SystemException {
162 boolean pagination = true;
163 FinderPath finderPath = null;
164 Object[] finderArgs = null;
165
166 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
167 (orderByComparator == null)) {
168 pagination = false;
169 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
170 finderArgs = new Object[] { uuid };
171 }
172 else {
173 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
174 finderArgs = new Object[] { uuid, start, end, orderByComparator };
175 }
176
177 List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(finderPath,
178 finderArgs, this);
179
180 if ((list != null) && !list.isEmpty()) {
181 for (AssetVocabulary assetVocabulary : list) {
182 if (!Validator.equals(uuid, assetVocabulary.getUuid())) {
183 list = null;
184
185 break;
186 }
187 }
188 }
189
190 if (list == null) {
191 StringBundler query = null;
192
193 if (orderByComparator != null) {
194 query = new StringBundler(3 +
195 (orderByComparator.getOrderByFields().length * 3));
196 }
197 else {
198 query = new StringBundler(3);
199 }
200
201 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
202
203 boolean bindUuid = false;
204
205 if (uuid == null) {
206 query.append(_FINDER_COLUMN_UUID_UUID_1);
207 }
208 else if (uuid.equals(StringPool.BLANK)) {
209 query.append(_FINDER_COLUMN_UUID_UUID_3);
210 }
211 else {
212 bindUuid = true;
213
214 query.append(_FINDER_COLUMN_UUID_UUID_2);
215 }
216
217 if (orderByComparator != null) {
218 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
219 orderByComparator);
220 }
221 else
222 if (pagination) {
223 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
224 }
225
226 String sql = query.toString();
227
228 Session session = null;
229
230 try {
231 session = openSession();
232
233 Query q = session.createQuery(sql);
234
235 QueryPos qPos = QueryPos.getInstance(q);
236
237 if (bindUuid) {
238 qPos.add(uuid);
239 }
240
241 if (!pagination) {
242 list = (List<AssetVocabulary>)QueryUtil.list(q,
243 getDialect(), start, end, false);
244
245 Collections.sort(list);
246
247 list = new UnmodifiableList<AssetVocabulary>(list);
248 }
249 else {
250 list = (List<AssetVocabulary>)QueryUtil.list(q,
251 getDialect(), start, end);
252 }
253
254 cacheResult(list);
255
256 FinderCacheUtil.putResult(finderPath, finderArgs, list);
257 }
258 catch (Exception e) {
259 FinderCacheUtil.removeResult(finderPath, finderArgs);
260
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266 }
267
268 return list;
269 }
270
271
280 @Override
281 public AssetVocabulary findByUuid_First(String uuid,
282 OrderByComparator orderByComparator)
283 throws NoSuchVocabularyException, SystemException {
284 AssetVocabulary assetVocabulary = fetchByUuid_First(uuid,
285 orderByComparator);
286
287 if (assetVocabulary != null) {
288 return assetVocabulary;
289 }
290
291 StringBundler msg = new StringBundler(4);
292
293 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
294
295 msg.append("uuid=");
296 msg.append(uuid);
297
298 msg.append(StringPool.CLOSE_CURLY_BRACE);
299
300 throw new NoSuchVocabularyException(msg.toString());
301 }
302
303
311 @Override
312 public AssetVocabulary fetchByUuid_First(String uuid,
313 OrderByComparator orderByComparator) throws SystemException {
314 List<AssetVocabulary> list = findByUuid(uuid, 0, 1, orderByComparator);
315
316 if (!list.isEmpty()) {
317 return list.get(0);
318 }
319
320 return null;
321 }
322
323
332 @Override
333 public AssetVocabulary findByUuid_Last(String uuid,
334 OrderByComparator orderByComparator)
335 throws NoSuchVocabularyException, SystemException {
336 AssetVocabulary assetVocabulary = fetchByUuid_Last(uuid,
337 orderByComparator);
338
339 if (assetVocabulary != null) {
340 return assetVocabulary;
341 }
342
343 StringBundler msg = new StringBundler(4);
344
345 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
346
347 msg.append("uuid=");
348 msg.append(uuid);
349
350 msg.append(StringPool.CLOSE_CURLY_BRACE);
351
352 throw new NoSuchVocabularyException(msg.toString());
353 }
354
355
363 @Override
364 public AssetVocabulary fetchByUuid_Last(String uuid,
365 OrderByComparator orderByComparator) throws SystemException {
366 int count = countByUuid(uuid);
367
368 if (count == 0) {
369 return null;
370 }
371
372 List<AssetVocabulary> list = findByUuid(uuid, count - 1, count,
373 orderByComparator);
374
375 if (!list.isEmpty()) {
376 return list.get(0);
377 }
378
379 return null;
380 }
381
382
392 @Override
393 public AssetVocabulary[] findByUuid_PrevAndNext(long vocabularyId,
394 String uuid, OrderByComparator orderByComparator)
395 throws NoSuchVocabularyException, SystemException {
396 AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
397
398 Session session = null;
399
400 try {
401 session = openSession();
402
403 AssetVocabulary[] array = new AssetVocabularyImpl[3];
404
405 array[0] = getByUuid_PrevAndNext(session, assetVocabulary, uuid,
406 orderByComparator, true);
407
408 array[1] = assetVocabulary;
409
410 array[2] = getByUuid_PrevAndNext(session, assetVocabulary, uuid,
411 orderByComparator, false);
412
413 return array;
414 }
415 catch (Exception e) {
416 throw processException(e);
417 }
418 finally {
419 closeSession(session);
420 }
421 }
422
423 protected AssetVocabulary getByUuid_PrevAndNext(Session session,
424 AssetVocabulary assetVocabulary, String uuid,
425 OrderByComparator orderByComparator, boolean previous) {
426 StringBundler query = null;
427
428 if (orderByComparator != null) {
429 query = new StringBundler(6 +
430 (orderByComparator.getOrderByFields().length * 6));
431 }
432 else {
433 query = new StringBundler(3);
434 }
435
436 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
437
438 boolean bindUuid = false;
439
440 if (uuid == null) {
441 query.append(_FINDER_COLUMN_UUID_UUID_1);
442 }
443 else if (uuid.equals(StringPool.BLANK)) {
444 query.append(_FINDER_COLUMN_UUID_UUID_3);
445 }
446 else {
447 bindUuid = true;
448
449 query.append(_FINDER_COLUMN_UUID_UUID_2);
450 }
451
452 if (orderByComparator != null) {
453 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
454
455 if (orderByConditionFields.length > 0) {
456 query.append(WHERE_AND);
457 }
458
459 for (int i = 0; i < orderByConditionFields.length; i++) {
460 query.append(_ORDER_BY_ENTITY_ALIAS);
461 query.append(orderByConditionFields[i]);
462
463 if ((i + 1) < orderByConditionFields.length) {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN_HAS_NEXT);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN_HAS_NEXT);
469 }
470 }
471 else {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(WHERE_GREATER_THAN);
474 }
475 else {
476 query.append(WHERE_LESSER_THAN);
477 }
478 }
479 }
480
481 query.append(ORDER_BY_CLAUSE);
482
483 String[] orderByFields = orderByComparator.getOrderByFields();
484
485 for (int i = 0; i < orderByFields.length; i++) {
486 query.append(_ORDER_BY_ENTITY_ALIAS);
487 query.append(orderByFields[i]);
488
489 if ((i + 1) < orderByFields.length) {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC_HAS_NEXT);
492 }
493 else {
494 query.append(ORDER_BY_DESC_HAS_NEXT);
495 }
496 }
497 else {
498 if (orderByComparator.isAscending() ^ previous) {
499 query.append(ORDER_BY_ASC);
500 }
501 else {
502 query.append(ORDER_BY_DESC);
503 }
504 }
505 }
506 }
507 else {
508 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
509 }
510
511 String sql = query.toString();
512
513 Query q = session.createQuery(sql);
514
515 q.setFirstResult(0);
516 q.setMaxResults(2);
517
518 QueryPos qPos = QueryPos.getInstance(q);
519
520 if (bindUuid) {
521 qPos.add(uuid);
522 }
523
524 if (orderByComparator != null) {
525 Object[] values = orderByComparator.getOrderByConditionValues(assetVocabulary);
526
527 for (Object value : values) {
528 qPos.add(value);
529 }
530 }
531
532 List<AssetVocabulary> list = q.list();
533
534 if (list.size() == 2) {
535 return list.get(1);
536 }
537 else {
538 return null;
539 }
540 }
541
542
548 @Override
549 public void removeByUuid(String uuid) throws SystemException {
550 for (AssetVocabulary assetVocabulary : findByUuid(uuid,
551 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
552 remove(assetVocabulary);
553 }
554 }
555
556
563 @Override
564 public int countByUuid(String uuid) throws SystemException {
565 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
566
567 Object[] finderArgs = new Object[] { uuid };
568
569 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
570 this);
571
572 if (count == null) {
573 StringBundler query = new StringBundler(2);
574
575 query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
576
577 boolean bindUuid = false;
578
579 if (uuid == null) {
580 query.append(_FINDER_COLUMN_UUID_UUID_1);
581 }
582 else if (uuid.equals(StringPool.BLANK)) {
583 query.append(_FINDER_COLUMN_UUID_UUID_3);
584 }
585 else {
586 bindUuid = true;
587
588 query.append(_FINDER_COLUMN_UUID_UUID_2);
589 }
590
591 String sql = query.toString();
592
593 Session session = null;
594
595 try {
596 session = openSession();
597
598 Query q = session.createQuery(sql);
599
600 QueryPos qPos = QueryPos.getInstance(q);
601
602 if (bindUuid) {
603 qPos.add(uuid);
604 }
605
606 count = (Long)q.uniqueResult();
607
608 FinderCacheUtil.putResult(finderPath, finderArgs, count);
609 }
610 catch (Exception e) {
611 FinderCacheUtil.removeResult(finderPath, finderArgs);
612
613 throw processException(e);
614 }
615 finally {
616 closeSession(session);
617 }
618 }
619
620 return count.intValue();
621 }
622
623 private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetVocabulary.uuid IS NULL";
624 private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetVocabulary.uuid = ?";
625 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = '')";
626 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
627 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
628 AssetVocabularyImpl.class, FINDER_CLASS_NAME_ENTITY,
629 "fetchByUUID_G",
630 new String[] { String.class.getName(), Long.class.getName() },
631 AssetVocabularyModelImpl.UUID_COLUMN_BITMASK |
632 AssetVocabularyModelImpl.GROUPID_COLUMN_BITMASK);
633 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
634 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
635 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
636 new String[] { String.class.getName(), Long.class.getName() });
637
638
647 @Override
648 public AssetVocabulary findByUUID_G(String uuid, long groupId)
649 throws NoSuchVocabularyException, SystemException {
650 AssetVocabulary assetVocabulary = fetchByUUID_G(uuid, groupId);
651
652 if (assetVocabulary == null) {
653 StringBundler msg = new StringBundler(6);
654
655 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
656
657 msg.append("uuid=");
658 msg.append(uuid);
659
660 msg.append(", groupId=");
661 msg.append(groupId);
662
663 msg.append(StringPool.CLOSE_CURLY_BRACE);
664
665 if (_log.isWarnEnabled()) {
666 _log.warn(msg.toString());
667 }
668
669 throw new NoSuchVocabularyException(msg.toString());
670 }
671
672 return assetVocabulary;
673 }
674
675
683 @Override
684 public AssetVocabulary fetchByUUID_G(String uuid, long groupId)
685 throws SystemException {
686 return fetchByUUID_G(uuid, groupId, true);
687 }
688
689
698 @Override
699 public AssetVocabulary fetchByUUID_G(String uuid, long groupId,
700 boolean retrieveFromCache) throws SystemException {
701 Object[] finderArgs = new Object[] { uuid, groupId };
702
703 Object result = null;
704
705 if (retrieveFromCache) {
706 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
707 finderArgs, this);
708 }
709
710 if (result instanceof AssetVocabulary) {
711 AssetVocabulary assetVocabulary = (AssetVocabulary)result;
712
713 if (!Validator.equals(uuid, assetVocabulary.getUuid()) ||
714 (groupId != assetVocabulary.getGroupId())) {
715 result = null;
716 }
717 }
718
719 if (result == null) {
720 StringBundler query = new StringBundler(4);
721
722 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
723
724 boolean bindUuid = false;
725
726 if (uuid == null) {
727 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
728 }
729 else if (uuid.equals(StringPool.BLANK)) {
730 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
731 }
732 else {
733 bindUuid = true;
734
735 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
736 }
737
738 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
739
740 String sql = query.toString();
741
742 Session session = null;
743
744 try {
745 session = openSession();
746
747 Query q = session.createQuery(sql);
748
749 QueryPos qPos = QueryPos.getInstance(q);
750
751 if (bindUuid) {
752 qPos.add(uuid);
753 }
754
755 qPos.add(groupId);
756
757 List<AssetVocabulary> list = q.list();
758
759 if (list.isEmpty()) {
760 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
761 finderArgs, list);
762 }
763 else {
764 AssetVocabulary assetVocabulary = list.get(0);
765
766 result = assetVocabulary;
767
768 cacheResult(assetVocabulary);
769
770 if ((assetVocabulary.getUuid() == null) ||
771 !assetVocabulary.getUuid().equals(uuid) ||
772 (assetVocabulary.getGroupId() != groupId)) {
773 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
774 finderArgs, assetVocabulary);
775 }
776 }
777 }
778 catch (Exception e) {
779 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
780 finderArgs);
781
782 throw processException(e);
783 }
784 finally {
785 closeSession(session);
786 }
787 }
788
789 if (result instanceof List<?>) {
790 return null;
791 }
792 else {
793 return (AssetVocabulary)result;
794 }
795 }
796
797
805 @Override
806 public AssetVocabulary removeByUUID_G(String uuid, long groupId)
807 throws NoSuchVocabularyException, SystemException {
808 AssetVocabulary assetVocabulary = findByUUID_G(uuid, groupId);
809
810 return remove(assetVocabulary);
811 }
812
813
821 @Override
822 public int countByUUID_G(String uuid, long groupId)
823 throws SystemException {
824 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
825
826 Object[] finderArgs = new Object[] { uuid, groupId };
827
828 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
829 this);
830
831 if (count == null) {
832 StringBundler query = new StringBundler(3);
833
834 query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
835
836 boolean bindUuid = false;
837
838 if (uuid == null) {
839 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
840 }
841 else if (uuid.equals(StringPool.BLANK)) {
842 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
843 }
844 else {
845 bindUuid = true;
846
847 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
848 }
849
850 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
851
852 String sql = query.toString();
853
854 Session session = null;
855
856 try {
857 session = openSession();
858
859 Query q = session.createQuery(sql);
860
861 QueryPos qPos = QueryPos.getInstance(q);
862
863 if (bindUuid) {
864 qPos.add(uuid);
865 }
866
867 qPos.add(groupId);
868
869 count = (Long)q.uniqueResult();
870
871 FinderCacheUtil.putResult(finderPath, finderArgs, count);
872 }
873 catch (Exception e) {
874 FinderCacheUtil.removeResult(finderPath, finderArgs);
875
876 throw processException(e);
877 }
878 finally {
879 closeSession(session);
880 }
881 }
882
883 return count.intValue();
884 }
885
886 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetVocabulary.uuid IS NULL AND ";
887 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetVocabulary.uuid = ? AND ";
888 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = '') AND ";
889 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetVocabulary.groupId = ?";
890 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
891 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
892 AssetVocabularyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
893 "findByUuid_C",
894 new String[] {
895 String.class.getName(), Long.class.getName(),
896
897 Integer.class.getName(), Integer.class.getName(),
898 OrderByComparator.class.getName()
899 });
900 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
901 new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
902 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
903 AssetVocabularyImpl.class,
904 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
905 new String[] { String.class.getName(), Long.class.getName() },
906 AssetVocabularyModelImpl.UUID_COLUMN_BITMASK |
907 AssetVocabularyModelImpl.COMPANYID_COLUMN_BITMASK |
908 AssetVocabularyModelImpl.NAME_COLUMN_BITMASK);
909 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
910 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
911 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
912 new String[] { String.class.getName(), Long.class.getName() });
913
914
922 @Override
923 public List<AssetVocabulary> findByUuid_C(String uuid, long companyId)
924 throws SystemException {
925 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
926 QueryUtil.ALL_POS, null);
927 }
928
929
943 @Override
944 public List<AssetVocabulary> findByUuid_C(String uuid, long companyId,
945 int start, int end) throws SystemException {
946 return findByUuid_C(uuid, companyId, start, end, null);
947 }
948
949
964 @Override
965 public List<AssetVocabulary> findByUuid_C(String uuid, long companyId,
966 int start, int end, OrderByComparator orderByComparator)
967 throws SystemException {
968 boolean pagination = true;
969 FinderPath finderPath = null;
970 Object[] finderArgs = null;
971
972 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
973 (orderByComparator == null)) {
974 pagination = false;
975 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
976 finderArgs = new Object[] { uuid, companyId };
977 }
978 else {
979 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
980 finderArgs = new Object[] {
981 uuid, companyId,
982
983 start, end, orderByComparator
984 };
985 }
986
987 List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(finderPath,
988 finderArgs, this);
989
990 if ((list != null) && !list.isEmpty()) {
991 for (AssetVocabulary assetVocabulary : list) {
992 if (!Validator.equals(uuid, assetVocabulary.getUuid()) ||
993 (companyId != assetVocabulary.getCompanyId())) {
994 list = null;
995
996 break;
997 }
998 }
999 }
1000
1001 if (list == null) {
1002 StringBundler query = null;
1003
1004 if (orderByComparator != null) {
1005 query = new StringBundler(4 +
1006 (orderByComparator.getOrderByFields().length * 3));
1007 }
1008 else {
1009 query = new StringBundler(4);
1010 }
1011
1012 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1013
1014 boolean bindUuid = false;
1015
1016 if (uuid == null) {
1017 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1018 }
1019 else if (uuid.equals(StringPool.BLANK)) {
1020 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1021 }
1022 else {
1023 bindUuid = true;
1024
1025 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1026 }
1027
1028 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1029
1030 if (orderByComparator != null) {
1031 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1032 orderByComparator);
1033 }
1034 else
1035 if (pagination) {
1036 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1037 }
1038
1039 String sql = query.toString();
1040
1041 Session session = null;
1042
1043 try {
1044 session = openSession();
1045
1046 Query q = session.createQuery(sql);
1047
1048 QueryPos qPos = QueryPos.getInstance(q);
1049
1050 if (bindUuid) {
1051 qPos.add(uuid);
1052 }
1053
1054 qPos.add(companyId);
1055
1056 if (!pagination) {
1057 list = (List<AssetVocabulary>)QueryUtil.list(q,
1058 getDialect(), start, end, false);
1059
1060 Collections.sort(list);
1061
1062 list = new UnmodifiableList<AssetVocabulary>(list);
1063 }
1064 else {
1065 list = (List<AssetVocabulary>)QueryUtil.list(q,
1066 getDialect(), start, end);
1067 }
1068
1069 cacheResult(list);
1070
1071 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1072 }
1073 catch (Exception e) {
1074 FinderCacheUtil.removeResult(finderPath, finderArgs);
1075
1076 throw processException(e);
1077 }
1078 finally {
1079 closeSession(session);
1080 }
1081 }
1082
1083 return list;
1084 }
1085
1086
1096 @Override
1097 public AssetVocabulary findByUuid_C_First(String uuid, long companyId,
1098 OrderByComparator orderByComparator)
1099 throws NoSuchVocabularyException, SystemException {
1100 AssetVocabulary assetVocabulary = fetchByUuid_C_First(uuid, companyId,
1101 orderByComparator);
1102
1103 if (assetVocabulary != null) {
1104 return assetVocabulary;
1105 }
1106
1107 StringBundler msg = new StringBundler(6);
1108
1109 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1110
1111 msg.append("uuid=");
1112 msg.append(uuid);
1113
1114 msg.append(", companyId=");
1115 msg.append(companyId);
1116
1117 msg.append(StringPool.CLOSE_CURLY_BRACE);
1118
1119 throw new NoSuchVocabularyException(msg.toString());
1120 }
1121
1122
1131 @Override
1132 public AssetVocabulary fetchByUuid_C_First(String uuid, long companyId,
1133 OrderByComparator orderByComparator) throws SystemException {
1134 List<AssetVocabulary> list = findByUuid_C(uuid, companyId, 0, 1,
1135 orderByComparator);
1136
1137 if (!list.isEmpty()) {
1138 return list.get(0);
1139 }
1140
1141 return null;
1142 }
1143
1144
1154 @Override
1155 public AssetVocabulary findByUuid_C_Last(String uuid, long companyId,
1156 OrderByComparator orderByComparator)
1157 throws NoSuchVocabularyException, SystemException {
1158 AssetVocabulary assetVocabulary = fetchByUuid_C_Last(uuid, companyId,
1159 orderByComparator);
1160
1161 if (assetVocabulary != null) {
1162 return assetVocabulary;
1163 }
1164
1165 StringBundler msg = new StringBundler(6);
1166
1167 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1168
1169 msg.append("uuid=");
1170 msg.append(uuid);
1171
1172 msg.append(", companyId=");
1173 msg.append(companyId);
1174
1175 msg.append(StringPool.CLOSE_CURLY_BRACE);
1176
1177 throw new NoSuchVocabularyException(msg.toString());
1178 }
1179
1180
1189 @Override
1190 public AssetVocabulary fetchByUuid_C_Last(String uuid, long companyId,
1191 OrderByComparator orderByComparator) throws SystemException {
1192 int count = countByUuid_C(uuid, companyId);
1193
1194 if (count == 0) {
1195 return null;
1196 }
1197
1198 List<AssetVocabulary> list = findByUuid_C(uuid, companyId, count - 1,
1199 count, orderByComparator);
1200
1201 if (!list.isEmpty()) {
1202 return list.get(0);
1203 }
1204
1205 return null;
1206 }
1207
1208
1219 @Override
1220 public AssetVocabulary[] findByUuid_C_PrevAndNext(long vocabularyId,
1221 String uuid, long companyId, OrderByComparator orderByComparator)
1222 throws NoSuchVocabularyException, SystemException {
1223 AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1224
1225 Session session = null;
1226
1227 try {
1228 session = openSession();
1229
1230 AssetVocabulary[] array = new AssetVocabularyImpl[3];
1231
1232 array[0] = getByUuid_C_PrevAndNext(session, assetVocabulary, uuid,
1233 companyId, orderByComparator, true);
1234
1235 array[1] = assetVocabulary;
1236
1237 array[2] = getByUuid_C_PrevAndNext(session, assetVocabulary, uuid,
1238 companyId, orderByComparator, false);
1239
1240 return array;
1241 }
1242 catch (Exception e) {
1243 throw processException(e);
1244 }
1245 finally {
1246 closeSession(session);
1247 }
1248 }
1249
1250 protected AssetVocabulary getByUuid_C_PrevAndNext(Session session,
1251 AssetVocabulary assetVocabulary, String uuid, long companyId,
1252 OrderByComparator orderByComparator, boolean previous) {
1253 StringBundler query = null;
1254
1255 if (orderByComparator != null) {
1256 query = new StringBundler(6 +
1257 (orderByComparator.getOrderByFields().length * 6));
1258 }
1259 else {
1260 query = new StringBundler(3);
1261 }
1262
1263 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1264
1265 boolean bindUuid = false;
1266
1267 if (uuid == null) {
1268 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1269 }
1270 else if (uuid.equals(StringPool.BLANK)) {
1271 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1272 }
1273 else {
1274 bindUuid = true;
1275
1276 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1277 }
1278
1279 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1280
1281 if (orderByComparator != null) {
1282 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1283
1284 if (orderByConditionFields.length > 0) {
1285 query.append(WHERE_AND);
1286 }
1287
1288 for (int i = 0; i < orderByConditionFields.length; i++) {
1289 query.append(_ORDER_BY_ENTITY_ALIAS);
1290 query.append(orderByConditionFields[i]);
1291
1292 if ((i + 1) < orderByConditionFields.length) {
1293 if (orderByComparator.isAscending() ^ previous) {
1294 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1295 }
1296 else {
1297 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1298 }
1299 }
1300 else {
1301 if (orderByComparator.isAscending() ^ previous) {
1302 query.append(WHERE_GREATER_THAN);
1303 }
1304 else {
1305 query.append(WHERE_LESSER_THAN);
1306 }
1307 }
1308 }
1309
1310 query.append(ORDER_BY_CLAUSE);
1311
1312 String[] orderByFields = orderByComparator.getOrderByFields();
1313
1314 for (int i = 0; i < orderByFields.length; i++) {
1315 query.append(_ORDER_BY_ENTITY_ALIAS);
1316 query.append(orderByFields[i]);
1317
1318 if ((i + 1) < orderByFields.length) {
1319 if (orderByComparator.isAscending() ^ previous) {
1320 query.append(ORDER_BY_ASC_HAS_NEXT);
1321 }
1322 else {
1323 query.append(ORDER_BY_DESC_HAS_NEXT);
1324 }
1325 }
1326 else {
1327 if (orderByComparator.isAscending() ^ previous) {
1328 query.append(ORDER_BY_ASC);
1329 }
1330 else {
1331 query.append(ORDER_BY_DESC);
1332 }
1333 }
1334 }
1335 }
1336 else {
1337 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1338 }
1339
1340 String sql = query.toString();
1341
1342 Query q = session.createQuery(sql);
1343
1344 q.setFirstResult(0);
1345 q.setMaxResults(2);
1346
1347 QueryPos qPos = QueryPos.getInstance(q);
1348
1349 if (bindUuid) {
1350 qPos.add(uuid);
1351 }
1352
1353 qPos.add(companyId);
1354
1355 if (orderByComparator != null) {
1356 Object[] values = orderByComparator.getOrderByConditionValues(assetVocabulary);
1357
1358 for (Object value : values) {
1359 qPos.add(value);
1360 }
1361 }
1362
1363 List<AssetVocabulary> list = q.list();
1364
1365 if (list.size() == 2) {
1366 return list.get(1);
1367 }
1368 else {
1369 return null;
1370 }
1371 }
1372
1373
1380 @Override
1381 public void removeByUuid_C(String uuid, long companyId)
1382 throws SystemException {
1383 for (AssetVocabulary assetVocabulary : findByUuid_C(uuid, companyId,
1384 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1385 remove(assetVocabulary);
1386 }
1387 }
1388
1389
1397 @Override
1398 public int countByUuid_C(String uuid, long companyId)
1399 throws SystemException {
1400 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1401
1402 Object[] finderArgs = new Object[] { uuid, companyId };
1403
1404 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1405 this);
1406
1407 if (count == null) {
1408 StringBundler query = new StringBundler(3);
1409
1410 query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1411
1412 boolean bindUuid = false;
1413
1414 if (uuid == null) {
1415 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1416 }
1417 else if (uuid.equals(StringPool.BLANK)) {
1418 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1419 }
1420 else {
1421 bindUuid = true;
1422
1423 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1424 }
1425
1426 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1427
1428 String sql = query.toString();
1429
1430 Session session = null;
1431
1432 try {
1433 session = openSession();
1434
1435 Query q = session.createQuery(sql);
1436
1437 QueryPos qPos = QueryPos.getInstance(q);
1438
1439 if (bindUuid) {
1440 qPos.add(uuid);
1441 }
1442
1443 qPos.add(companyId);
1444
1445 count = (Long)q.uniqueResult();
1446
1447 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1448 }
1449 catch (Exception e) {
1450 FinderCacheUtil.removeResult(finderPath, finderArgs);
1451
1452 throw processException(e);
1453 }
1454 finally {
1455 closeSession(session);
1456 }
1457 }
1458
1459 return count.intValue();
1460 }
1461
1462 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "assetVocabulary.uuid IS NULL AND ";
1463 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "assetVocabulary.uuid = ? AND ";
1464 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = '') AND ";
1465 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "assetVocabulary.companyId = ?";
1466 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
1467 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
1468 AssetVocabularyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1469 "findByGroupId",
1470 new String[] {
1471 Long.class.getName(),
1472
1473 Integer.class.getName(), Integer.class.getName(),
1474 OrderByComparator.class.getName()
1475 });
1476 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1477 new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
1478 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
1479 AssetVocabularyImpl.class,
1480 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1481 new String[] { Long.class.getName() },
1482 AssetVocabularyModelImpl.GROUPID_COLUMN_BITMASK |
1483 AssetVocabularyModelImpl.NAME_COLUMN_BITMASK);
1484 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
1485 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1486 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1487 new String[] { Long.class.getName() });
1488
1489
1496 @Override
1497 public List<AssetVocabulary> findByGroupId(long groupId)
1498 throws SystemException {
1499 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1500 }
1501
1502
1515 @Override
1516 public List<AssetVocabulary> findByGroupId(long groupId, int start, int end)
1517 throws SystemException {
1518 return findByGroupId(groupId, start, end, null);
1519 }
1520
1521
1535 @Override
1536 public List<AssetVocabulary> findByGroupId(long groupId, int start,
1537 int end, OrderByComparator orderByComparator) throws SystemException {
1538 boolean pagination = true;
1539 FinderPath finderPath = null;
1540 Object[] finderArgs = null;
1541
1542 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1543 (orderByComparator == null)) {
1544 pagination = false;
1545 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1546 finderArgs = new Object[] { groupId };
1547 }
1548 else {
1549 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1550 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1551 }
1552
1553 List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(finderPath,
1554 finderArgs, this);
1555
1556 if ((list != null) && !list.isEmpty()) {
1557 for (AssetVocabulary assetVocabulary : list) {
1558 if ((groupId != assetVocabulary.getGroupId())) {
1559 list = null;
1560
1561 break;
1562 }
1563 }
1564 }
1565
1566 if (list == null) {
1567 StringBundler query = null;
1568
1569 if (orderByComparator != null) {
1570 query = new StringBundler(3 +
1571 (orderByComparator.getOrderByFields().length * 3));
1572 }
1573 else {
1574 query = new StringBundler(3);
1575 }
1576
1577 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1578
1579 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1580
1581 if (orderByComparator != null) {
1582 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1583 orderByComparator);
1584 }
1585 else
1586 if (pagination) {
1587 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1588 }
1589
1590 String sql = query.toString();
1591
1592 Session session = null;
1593
1594 try {
1595 session = openSession();
1596
1597 Query q = session.createQuery(sql);
1598
1599 QueryPos qPos = QueryPos.getInstance(q);
1600
1601 qPos.add(groupId);
1602
1603 if (!pagination) {
1604 list = (List<AssetVocabulary>)QueryUtil.list(q,
1605 getDialect(), start, end, false);
1606
1607 Collections.sort(list);
1608
1609 list = new UnmodifiableList<AssetVocabulary>(list);
1610 }
1611 else {
1612 list = (List<AssetVocabulary>)QueryUtil.list(q,
1613 getDialect(), start, end);
1614 }
1615
1616 cacheResult(list);
1617
1618 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1619 }
1620 catch (Exception e) {
1621 FinderCacheUtil.removeResult(finderPath, finderArgs);
1622
1623 throw processException(e);
1624 }
1625 finally {
1626 closeSession(session);
1627 }
1628 }
1629
1630 return list;
1631 }
1632
1633
1642 @Override
1643 public AssetVocabulary findByGroupId_First(long groupId,
1644 OrderByComparator orderByComparator)
1645 throws NoSuchVocabularyException, SystemException {
1646 AssetVocabulary assetVocabulary = fetchByGroupId_First(groupId,
1647 orderByComparator);
1648
1649 if (assetVocabulary != null) {
1650 return assetVocabulary;
1651 }
1652
1653 StringBundler msg = new StringBundler(4);
1654
1655 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1656
1657 msg.append("groupId=");
1658 msg.append(groupId);
1659
1660 msg.append(StringPool.CLOSE_CURLY_BRACE);
1661
1662 throw new NoSuchVocabularyException(msg.toString());
1663 }
1664
1665
1673 @Override
1674 public AssetVocabulary fetchByGroupId_First(long groupId,
1675 OrderByComparator orderByComparator) throws SystemException {
1676 List<AssetVocabulary> list = findByGroupId(groupId, 0, 1,
1677 orderByComparator);
1678
1679 if (!list.isEmpty()) {
1680 return list.get(0);
1681 }
1682
1683 return null;
1684 }
1685
1686
1695 @Override
1696 public AssetVocabulary findByGroupId_Last(long groupId,
1697 OrderByComparator orderByComparator)
1698 throws NoSuchVocabularyException, SystemException {
1699 AssetVocabulary assetVocabulary = fetchByGroupId_Last(groupId,
1700 orderByComparator);
1701
1702 if (assetVocabulary != null) {
1703 return assetVocabulary;
1704 }
1705
1706 StringBundler msg = new StringBundler(4);
1707
1708 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1709
1710 msg.append("groupId=");
1711 msg.append(groupId);
1712
1713 msg.append(StringPool.CLOSE_CURLY_BRACE);
1714
1715 throw new NoSuchVocabularyException(msg.toString());
1716 }
1717
1718
1726 @Override
1727 public AssetVocabulary fetchByGroupId_Last(long groupId,
1728 OrderByComparator orderByComparator) throws SystemException {
1729 int count = countByGroupId(groupId);
1730
1731 if (count == 0) {
1732 return null;
1733 }
1734
1735 List<AssetVocabulary> list = findByGroupId(groupId, count - 1, count,
1736 orderByComparator);
1737
1738 if (!list.isEmpty()) {
1739 return list.get(0);
1740 }
1741
1742 return null;
1743 }
1744
1745
1755 @Override
1756 public AssetVocabulary[] findByGroupId_PrevAndNext(long vocabularyId,
1757 long groupId, OrderByComparator orderByComparator)
1758 throws NoSuchVocabularyException, SystemException {
1759 AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1760
1761 Session session = null;
1762
1763 try {
1764 session = openSession();
1765
1766 AssetVocabulary[] array = new AssetVocabularyImpl[3];
1767
1768 array[0] = getByGroupId_PrevAndNext(session, assetVocabulary,
1769 groupId, orderByComparator, true);
1770
1771 array[1] = assetVocabulary;
1772
1773 array[2] = getByGroupId_PrevAndNext(session, assetVocabulary,
1774 groupId, orderByComparator, false);
1775
1776 return array;
1777 }
1778 catch (Exception e) {
1779 throw processException(e);
1780 }
1781 finally {
1782 closeSession(session);
1783 }
1784 }
1785
1786 protected AssetVocabulary getByGroupId_PrevAndNext(Session session,
1787 AssetVocabulary assetVocabulary, long groupId,
1788 OrderByComparator orderByComparator, boolean previous) {
1789 StringBundler query = null;
1790
1791 if (orderByComparator != null) {
1792 query = new StringBundler(6 +
1793 (orderByComparator.getOrderByFields().length * 6));
1794 }
1795 else {
1796 query = new StringBundler(3);
1797 }
1798
1799 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1800
1801 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1802
1803 if (orderByComparator != null) {
1804 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1805
1806 if (orderByConditionFields.length > 0) {
1807 query.append(WHERE_AND);
1808 }
1809
1810 for (int i = 0; i < orderByConditionFields.length; i++) {
1811 query.append(_ORDER_BY_ENTITY_ALIAS);
1812 query.append(orderByConditionFields[i]);
1813
1814 if ((i + 1) < orderByConditionFields.length) {
1815 if (orderByComparator.isAscending() ^ previous) {
1816 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1817 }
1818 else {
1819 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1820 }
1821 }
1822 else {
1823 if (orderByComparator.isAscending() ^ previous) {
1824 query.append(WHERE_GREATER_THAN);
1825 }
1826 else {
1827 query.append(WHERE_LESSER_THAN);
1828 }
1829 }
1830 }
1831
1832 query.append(ORDER_BY_CLAUSE);
1833
1834 String[] orderByFields = orderByComparator.getOrderByFields();
1835
1836 for (int i = 0; i < orderByFields.length; i++) {
1837 query.append(_ORDER_BY_ENTITY_ALIAS);
1838 query.append(orderByFields[i]);
1839
1840 if ((i + 1) < orderByFields.length) {
1841 if (orderByComparator.isAscending() ^ previous) {
1842 query.append(ORDER_BY_ASC_HAS_NEXT);
1843 }
1844 else {
1845 query.append(ORDER_BY_DESC_HAS_NEXT);
1846 }
1847 }
1848 else {
1849 if (orderByComparator.isAscending() ^ previous) {
1850 query.append(ORDER_BY_ASC);
1851 }
1852 else {
1853 query.append(ORDER_BY_DESC);
1854 }
1855 }
1856 }
1857 }
1858 else {
1859 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1860 }
1861
1862 String sql = query.toString();
1863
1864 Query q = session.createQuery(sql);
1865
1866 q.setFirstResult(0);
1867 q.setMaxResults(2);
1868
1869 QueryPos qPos = QueryPos.getInstance(q);
1870
1871 qPos.add(groupId);
1872
1873 if (orderByComparator != null) {
1874 Object[] values = orderByComparator.getOrderByConditionValues(assetVocabulary);
1875
1876 for (Object value : values) {
1877 qPos.add(value);
1878 }
1879 }
1880
1881 List<AssetVocabulary> list = q.list();
1882
1883 if (list.size() == 2) {
1884 return list.get(1);
1885 }
1886 else {
1887 return null;
1888 }
1889 }
1890
1891
1898 @Override
1899 public List<AssetVocabulary> filterFindByGroupId(long groupId)
1900 throws SystemException {
1901 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1902 QueryUtil.ALL_POS, null);
1903 }
1904
1905
1918 @Override
1919 public List<AssetVocabulary> filterFindByGroupId(long groupId, int start,
1920 int end) throws SystemException {
1921 return filterFindByGroupId(groupId, start, end, null);
1922 }
1923
1924
1938 @Override
1939 public List<AssetVocabulary> filterFindByGroupId(long groupId, int start,
1940 int end, OrderByComparator orderByComparator) throws SystemException {
1941 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1942 return findByGroupId(groupId, start, end, orderByComparator);
1943 }
1944
1945 StringBundler query = null;
1946
1947 if (orderByComparator != null) {
1948 query = new StringBundler(3 +
1949 (orderByComparator.getOrderByFields().length * 3));
1950 }
1951 else {
1952 query = new StringBundler(3);
1953 }
1954
1955 if (getDB().isSupportsInlineDistinct()) {
1956 query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE);
1957 }
1958 else {
1959 query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_NO_INLINE_DISTINCT_WHERE_1);
1960 }
1961
1962 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1963
1964 if (!getDB().isSupportsInlineDistinct()) {
1965 query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_NO_INLINE_DISTINCT_WHERE_2);
1966 }
1967
1968 if (orderByComparator != null) {
1969 if (getDB().isSupportsInlineDistinct()) {
1970 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1971 orderByComparator, true);
1972 }
1973 else {
1974 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1975 orderByComparator, true);
1976 }
1977 }
1978 else {
1979 if (getDB().isSupportsInlineDistinct()) {
1980 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1981 }
1982 else {
1983 query.append(AssetVocabularyModelImpl.ORDER_BY_SQL);
1984 }
1985 }
1986
1987 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1988 AssetVocabulary.class.getName(),
1989 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1990
1991 Session session = null;
1992
1993 try {
1994 session = openSession();
1995
1996 SQLQuery q = session.createSQLQuery(sql);
1997
1998 if (getDB().isSupportsInlineDistinct()) {
1999 q.addEntity(_FILTER_ENTITY_ALIAS, AssetVocabularyImpl.class);
2000 }
2001 else {
2002 q.addEntity(_FILTER_ENTITY_TABLE, AssetVocabularyImpl.class);
2003 }
2004
2005 QueryPos qPos = QueryPos.getInstance(q);
2006
2007 qPos.add(groupId);
2008
2009 return (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
2010 start, end);
2011 }
2012 catch (Exception e) {
2013 throw processException(e);
2014 }
2015 finally {
2016 closeSession(session);
2017 }
2018 }
2019
2020
2030 @Override
2031 public AssetVocabulary[] filterFindByGroupId_PrevAndNext(
2032 long vocabularyId, long groupId, OrderByComparator orderByComparator)
2033 throws NoSuchVocabularyException, SystemException {
2034 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2035 return findByGroupId_PrevAndNext(vocabularyId, groupId,
2036 orderByComparator);
2037 }
2038
2039 AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
2040
2041 Session session = null;
2042
2043 try {
2044 session = openSession();
2045
2046 AssetVocabulary[] array = new AssetVocabularyImpl[3];
2047
2048 array[0] = filterGetByGroupId_PrevAndNext(session, assetVocabulary,
2049 groupId, orderByComparator, true);
2050
2051 array[1] = assetVocabulary;
2052
2053 array[2] = filterGetByGroupId_PrevAndNext(session, assetVocabulary,
2054 groupId, orderByComparator, false);
2055
2056 return array;
2057 }
2058 catch (Exception e) {
2059 throw processException(e);
2060 }
2061 finally {
2062 closeSession(session);
2063 }
2064 }
2065
2066 protected AssetVocabulary filterGetByGroupId_PrevAndNext(Session session,
2067 AssetVocabulary assetVocabulary, long groupId,
2068 OrderByComparator orderByComparator, boolean previous) {
2069 StringBundler query = null;
2070
2071 if (orderByComparator != null) {
2072 query = new StringBundler(6 +
2073 (orderByComparator.getOrderByFields().length * 6));
2074 }
2075 else {
2076 query = new StringBundler(3);
2077 }
2078
2079 if (getDB().isSupportsInlineDistinct()) {
2080 query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE);
2081 }
2082 else {
2083 query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_NO_INLINE_DISTINCT_WHERE_1);
2084 }
2085
2086 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2087
2088 if (!getDB().isSupportsInlineDistinct()) {
2089 query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_NO_INLINE_DISTINCT_WHERE_2);
2090 }
2091
2092 if (orderByComparator != null) {
2093 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2094
2095 if (orderByConditionFields.length > 0) {
2096 query.append(WHERE_AND);
2097 }
2098
2099 for (int i = 0; i < orderByConditionFields.length; i++) {
2100 if (getDB().isSupportsInlineDistinct()) {
2101 query.append(_ORDER_BY_ENTITY_ALIAS);
2102 }
2103 else {
2104 query.append(_ORDER_BY_ENTITY_TABLE);
2105 }
2106
2107 query.append(orderByConditionFields[i]);
2108
2109 if ((i + 1) < orderByConditionFields.length) {
2110 if (orderByComparator.isAscending() ^ previous) {
2111 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2112 }
2113 else {
2114 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2115 }
2116 }
2117 else {
2118 if (orderByComparator.isAscending() ^ previous) {
2119 query.append(WHERE_GREATER_THAN);
2120 }
2121 else {
2122 query.append(WHERE_LESSER_THAN);
2123 }
2124 }
2125 }
2126
2127 query.append(ORDER_BY_CLAUSE);
2128
2129 String[] orderByFields = orderByComparator.getOrderByFields();
2130
2131 for (int i = 0; i < orderByFields.length; i++) {
2132 if (getDB().isSupportsInlineDistinct()) {
2133 query.append(_ORDER_BY_ENTITY_ALIAS);
2134 }
2135 else {
2136 query.append(_ORDER_BY_ENTITY_TABLE);
2137 }
2138
2139 query.append(orderByFields[i]);
2140
2141 if ((i + 1) < orderByFields.length) {
2142 if (orderByComparator.isAscending() ^ previous) {
2143 query.append(ORDER_BY_ASC_HAS_NEXT);
2144 }
2145 else {
2146 query.append(ORDER_BY_DESC_HAS_NEXT);
2147 }
2148 }
2149 else {
2150 if (orderByComparator.isAscending() ^ previous) {
2151 query.append(ORDER_BY_ASC);
2152 }
2153 else {
2154 query.append(ORDER_BY_DESC);
2155 }
2156 }
2157 }
2158 }
2159 else {
2160 if (getDB().isSupportsInlineDistinct()) {
2161 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
2162 }
2163 else {
2164 query.append(AssetVocabularyModelImpl.ORDER_BY_SQL);
2165 }
2166 }
2167
2168 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2169 AssetVocabulary.class.getName(),
2170 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2171
2172 SQLQuery q = session.createSQLQuery(sql);
2173
2174 q.setFirstResult(0);
2175 q.setMaxResults(2);
2176
2177 if (getDB().isSupportsInlineDistinct()) {
2178 q.addEntity(_FILTER_ENTITY_ALIAS, AssetVocabularyImpl.class);
2179 }
2180 else {
2181 q.addEntity(_FILTER_ENTITY_TABLE, AssetVocabularyImpl.class);
2182 }
2183
2184 QueryPos qPos = QueryPos.getInstance(q);
2185
2186 qPos.add(groupId);
2187
2188 if (orderByComparator != null) {
2189 Object[] values = orderByComparator.getOrderByConditionValues(assetVocabulary);
2190
2191 for (Object value : values) {
2192 qPos.add(value);
2193 }
2194 }
2195
2196 List<AssetVocabulary> list = q.list();
2197
2198 if (list.size() == 2) {
2199 return list.get(1);
2200 }
2201 else {
2202 return null;
2203 }
2204 }
2205
2206
2212 @Override
2213 public void removeByGroupId(long groupId) throws SystemException {
2214 for (AssetVocabulary assetVocabulary : findByGroupId(groupId,
2215 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2216 remove(assetVocabulary);
2217 }
2218 }
2219
2220
2227 @Override
2228 public int countByGroupId(long groupId) throws SystemException {
2229 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2230
2231 Object[] finderArgs = new Object[] { groupId };
2232
2233 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2234 this);
2235
2236 if (count == null) {
2237 StringBundler query = new StringBundler(2);
2238
2239 query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2240
2241 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2242
2243 String sql = query.toString();
2244
2245 Session session = null;
2246
2247 try {
2248 session = openSession();
2249
2250 Query q = session.createQuery(sql);
2251
2252 QueryPos qPos = QueryPos.getInstance(q);
2253
2254 qPos.add(groupId);
2255
2256 count = (Long)q.uniqueResult();
2257
2258 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2259 }
2260 catch (Exception e) {
2261 FinderCacheUtil.removeResult(finderPath, finderArgs);
2262
2263 throw processException(e);
2264 }
2265 finally {
2266 closeSession(session);
2267 }
2268 }
2269
2270 return count.intValue();
2271 }
2272
2273
2280 @Override
2281 public int filterCountByGroupId(long groupId) throws SystemException {
2282 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2283 return countByGroupId(groupId);
2284 }
2285
2286 StringBundler query = new StringBundler(2);
2287
2288 query.append(_FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE);
2289
2290 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2291
2292 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2293 AssetVocabulary.class.getName(),
2294 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2295
2296 Session session = null;
2297
2298 try {
2299 session = openSession();
2300
2301 SQLQuery q = session.createSQLQuery(sql);
2302
2303 q.addScalar(COUNT_COLUMN_NAME,
2304 com.liferay.portal.kernel.dao.orm.Type.LONG);
2305
2306 QueryPos qPos = QueryPos.getInstance(q);
2307
2308 qPos.add(groupId);
2309
2310 Long count = (Long)q.uniqueResult();
2311
2312 return count.intValue();
2313 }
2314 catch (Exception e) {
2315 throw processException(e);
2316 }
2317 finally {
2318 closeSession(session);
2319 }
2320 }
2321
2322 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetVocabulary.groupId = ?";
2323 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2324 new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
2325 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
2326 AssetVocabularyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2327 "findByCompanyId",
2328 new String[] {
2329 Long.class.getName(),
2330
2331 Integer.class.getName(), Integer.class.getName(),
2332 OrderByComparator.class.getName()
2333 });
2334 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2335 new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
2336 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
2337 AssetVocabularyImpl.class,
2338 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2339 new String[] { Long.class.getName() },
2340 AssetVocabularyModelImpl.COMPANYID_COLUMN_BITMASK |
2341 AssetVocabularyModelImpl.NAME_COLUMN_BITMASK);
2342 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
2343 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
2344 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2345 new String[] { Long.class.getName() });
2346
2347
2354 @Override
2355 public List<AssetVocabulary> findByCompanyId(long companyId)
2356 throws SystemException {
2357 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2358 null);
2359 }
2360
2361
2374 @Override
2375 public List<AssetVocabulary> findByCompanyId(long companyId, int start,
2376 int end) throws SystemException {
2377 return findByCompanyId(companyId, start, end, null);
2378 }
2379
2380
2394 @Override
2395 public List<AssetVocabulary> findByCompanyId(long companyId, int start,
2396 int end, OrderByComparator orderByComparator) throws SystemException {
2397 boolean pagination = true;
2398 FinderPath finderPath = null;
2399 Object[] finderArgs = null;
2400
2401 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2402 (orderByComparator == null)) {
2403 pagination = false;
2404 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2405 finderArgs = new Object[] { companyId };
2406 }
2407 else {
2408 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2409 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2410 }
2411
2412 List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(finderPath,
2413 finderArgs, this);
2414
2415 if ((list != null) && !list.isEmpty()) {
2416 for (AssetVocabulary assetVocabulary : list) {
2417 if ((companyId != assetVocabulary.getCompanyId())) {
2418 list = null;
2419
2420 break;
2421 }
2422 }
2423 }
2424
2425 if (list == null) {
2426 StringBundler query = null;
2427
2428 if (orderByComparator != null) {
2429 query = new StringBundler(3 +
2430 (orderByComparator.getOrderByFields().length * 3));
2431 }
2432 else {
2433 query = new StringBundler(3);
2434 }
2435
2436 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
2437
2438 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2439
2440 if (orderByComparator != null) {
2441 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2442 orderByComparator);
2443 }
2444 else
2445 if (pagination) {
2446 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
2447 }
2448
2449 String sql = query.toString();
2450
2451 Session session = null;
2452
2453 try {
2454 session = openSession();
2455
2456 Query q = session.createQuery(sql);
2457
2458 QueryPos qPos = QueryPos.getInstance(q);
2459
2460 qPos.add(companyId);
2461
2462 if (!pagination) {
2463 list = (List<AssetVocabulary>)QueryUtil.list(q,
2464 getDialect(), start, end, false);
2465
2466 Collections.sort(list);
2467
2468 list = new UnmodifiableList<AssetVocabulary>(list);
2469 }
2470 else {
2471 list = (List<AssetVocabulary>)QueryUtil.list(q,
2472 getDialect(), start, end);
2473 }
2474
2475 cacheResult(list);
2476
2477 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2478 }
2479 catch (Exception e) {
2480 FinderCacheUtil.removeResult(finderPath, finderArgs);
2481
2482 throw processException(e);
2483 }
2484 finally {
2485 closeSession(session);
2486 }
2487 }
2488
2489 return list;
2490 }
2491
2492
2501 @Override
2502 public AssetVocabulary findByCompanyId_First(long companyId,
2503 OrderByComparator orderByComparator)
2504 throws NoSuchVocabularyException, SystemException {
2505 AssetVocabulary assetVocabulary = fetchByCompanyId_First(companyId,
2506 orderByComparator);
2507
2508 if (assetVocabulary != null) {
2509 return assetVocabulary;
2510 }
2511
2512 StringBundler msg = new StringBundler(4);
2513
2514 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2515
2516 msg.append("companyId=");
2517 msg.append(companyId);
2518
2519 msg.append(StringPool.CLOSE_CURLY_BRACE);
2520
2521 throw new NoSuchVocabularyException(msg.toString());
2522 }
2523
2524
2532 @Override
2533 public AssetVocabulary fetchByCompanyId_First(long companyId,
2534 OrderByComparator orderByComparator) throws SystemException {
2535 List<AssetVocabulary> list = findByCompanyId(companyId, 0, 1,
2536 orderByComparator);
2537
2538 if (!list.isEmpty()) {
2539 return list.get(0);
2540 }
2541
2542 return null;
2543 }
2544
2545
2554 @Override
2555 public AssetVocabulary findByCompanyId_Last(long companyId,
2556 OrderByComparator orderByComparator)
2557 throws NoSuchVocabularyException, SystemException {
2558 AssetVocabulary assetVocabulary = fetchByCompanyId_Last(companyId,
2559 orderByComparator);
2560
2561 if (assetVocabulary != null) {
2562 return assetVocabulary;
2563 }
2564
2565 StringBundler msg = new StringBundler(4);
2566
2567 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2568
2569 msg.append("companyId=");
2570 msg.append(companyId);
2571
2572 msg.append(StringPool.CLOSE_CURLY_BRACE);
2573
2574 throw new NoSuchVocabularyException(msg.toString());
2575 }
2576
2577
2585 @Override
2586 public AssetVocabulary fetchByCompanyId_Last(long companyId,
2587 OrderByComparator orderByComparator) throws SystemException {
2588 int count = countByCompanyId(companyId);
2589
2590 if (count == 0) {
2591 return null;
2592 }
2593
2594 List<AssetVocabulary> list = findByCompanyId(companyId, count - 1,
2595 count, orderByComparator);
2596
2597 if (!list.isEmpty()) {
2598 return list.get(0);
2599 }
2600
2601 return null;
2602 }
2603
2604
2614 @Override
2615 public AssetVocabulary[] findByCompanyId_PrevAndNext(long vocabularyId,
2616 long companyId, OrderByComparator orderByComparator)
2617 throws NoSuchVocabularyException, SystemException {
2618 AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
2619
2620 Session session = null;
2621
2622 try {
2623 session = openSession();
2624
2625 AssetVocabulary[] array = new AssetVocabularyImpl[3];
2626
2627 array[0] = getByCompanyId_PrevAndNext(session, assetVocabulary,
2628 companyId, orderByComparator, true);
2629
2630 array[1] = assetVocabulary;
2631
2632 array[2] = getByCompanyId_PrevAndNext(session, assetVocabulary,
2633 companyId, orderByComparator, false);
2634
2635 return array;
2636 }
2637 catch (Exception e) {
2638 throw processException(e);
2639 }
2640 finally {
2641 closeSession(session);
2642 }
2643 }
2644
2645 protected AssetVocabulary getByCompanyId_PrevAndNext(Session session,
2646 AssetVocabulary assetVocabulary, long companyId,
2647 OrderByComparator orderByComparator, boolean previous) {
2648 StringBundler query = null;
2649
2650 if (orderByComparator != null) {
2651 query = new StringBundler(6 +
2652 (orderByComparator.getOrderByFields().length * 6));
2653 }
2654 else {
2655 query = new StringBundler(3);
2656 }
2657
2658 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
2659
2660 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2661
2662 if (orderByComparator != null) {
2663 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2664
2665 if (orderByConditionFields.length > 0) {
2666 query.append(WHERE_AND);
2667 }
2668
2669 for (int i = 0; i < orderByConditionFields.length; i++) {
2670 query.append(_ORDER_BY_ENTITY_ALIAS);
2671 query.append(orderByConditionFields[i]);
2672
2673 if ((i + 1) < orderByConditionFields.length) {
2674 if (orderByComparator.isAscending() ^ previous) {
2675 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2676 }
2677 else {
2678 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2679 }
2680 }
2681 else {
2682 if (orderByComparator.isAscending() ^ previous) {
2683 query.append(WHERE_GREATER_THAN);
2684 }
2685 else {
2686 query.append(WHERE_LESSER_THAN);
2687 }
2688 }
2689 }
2690
2691 query.append(ORDER_BY_CLAUSE);
2692
2693 String[] orderByFields = orderByComparator.getOrderByFields();
2694
2695 for (int i = 0; i < orderByFields.length; i++) {
2696 query.append(_ORDER_BY_ENTITY_ALIAS);
2697 query.append(orderByFields[i]);
2698
2699 if ((i + 1) < orderByFields.length) {
2700 if (orderByComparator.isAscending() ^ previous) {
2701 query.append(ORDER_BY_ASC_HAS_NEXT);
2702 }
2703 else {
2704 query.append(ORDER_BY_DESC_HAS_NEXT);
2705 }
2706 }
2707 else {
2708 if (orderByComparator.isAscending() ^ previous) {
2709 query.append(ORDER_BY_ASC);
2710 }
2711 else {
2712 query.append(ORDER_BY_DESC);
2713 }
2714 }
2715 }
2716 }
2717 else {
2718 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
2719 }
2720
2721 String sql = query.toString();
2722
2723 Query q = session.createQuery(sql);
2724
2725 q.setFirstResult(0);
2726 q.setMaxResults(2);
2727
2728 QueryPos qPos = QueryPos.getInstance(q);
2729
2730 qPos.add(companyId);
2731
2732 if (orderByComparator != null) {
2733 Object[] values = orderByComparator.getOrderByConditionValues(assetVocabulary);
2734
2735 for (Object value : values) {
2736 qPos.add(value);
2737 }
2738 }
2739
2740 List<AssetVocabulary> list = q.list();
2741
2742 if (list.size() == 2) {
2743 return list.get(1);
2744 }
2745 else {
2746 return null;
2747 }
2748 }
2749
2750
2756 @Override
2757 public void removeByCompanyId(long companyId) throws SystemException {
2758 for (AssetVocabulary assetVocabulary : findByCompanyId(companyId,
2759 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2760 remove(assetVocabulary);
2761 }
2762 }
2763
2764
2771 @Override
2772 public int countByCompanyId(long companyId) throws SystemException {
2773 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2774
2775 Object[] finderArgs = new Object[] { companyId };
2776
2777 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2778 this);
2779
2780 if (count == null) {
2781 StringBundler query = new StringBundler(2);
2782
2783 query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2784
2785 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2786
2787 String sql = query.toString();
2788
2789 Session session = null;
2790
2791 try {
2792 session = openSession();
2793
2794 Query q = session.createQuery(sql);
2795
2796 QueryPos qPos = QueryPos.getInstance(q);
2797
2798 qPos.add(companyId);
2799
2800 count = (Long)q.uniqueResult();
2801
2802 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2803 }
2804 catch (Exception e) {
2805 FinderCacheUtil.removeResult(finderPath, finderArgs);
2806
2807 throw processException(e);
2808 }
2809 finally {
2810 closeSession(session);
2811 }
2812 }
2813
2814 return count.intValue();
2815 }
2816
2817 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetVocabulary.companyId = ?";
2818 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
2819 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
2820 AssetVocabularyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
2821 new String[] { Long.class.getName(), String.class.getName() },
2822 AssetVocabularyModelImpl.GROUPID_COLUMN_BITMASK |
2823 AssetVocabularyModelImpl.NAME_COLUMN_BITMASK);
2824 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
2825 AssetVocabularyModelImpl.FINDER_CACHE_ENABLED, Long.class,
2826 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
2827 new String[] { Long.class.getName(), String.class.getName() });
2828
2829
2838 @Override
2839 public AssetVocabulary findByG_N(long groupId, String name)
2840 throws NoSuchVocabularyException, SystemException {
2841 AssetVocabulary assetVocabulary = fetchByG_N(groupId, name);
2842
2843 if (assetVocabulary == null) {
2844 StringBundler msg = new StringBundler(6);
2845
2846 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2847
2848 msg.append("groupId=");
2849 msg.append(groupId);
2850
2851 msg.append(", name=");
2852 msg.append(name);
2853
2854 msg.append(StringPool.CLOSE_CURLY_BRACE);
2855
2856 if (_log.isWarnEnabled()) {
2857 _log.warn(msg.toString());
2858 }
2859
2860 throw new NoSuchVocabularyException(msg.toString());
2861 }
2862
2863 return assetVocabulary;
2864 }
2865
2866
2874 @Override
2875 public AssetVocabulary fetchByG_N(long groupId, String name)
2876 throws SystemException {
2877 return fetchByG_N(groupId, name, true);
2878 }
2879
2880
2889 @Override
2890 public AssetVocabulary fetchByG_N(long groupId, String name,
2891 boolean retrieveFromCache) throws SystemException {
2892 Object[] finderArgs = new Object[] { groupId, name };
2893
2894 Object result = null;
2895
2896 if (retrieveFromCache) {
2897 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
2898 finderArgs, this);
2899 }
2900
2901 if (result instanceof AssetVocabulary) {
2902 AssetVocabulary assetVocabulary = (AssetVocabulary)result;
2903
2904 if ((groupId != assetVocabulary.getGroupId()) ||
2905 !Validator.equals(name, assetVocabulary.getName())) {
2906 result = null;
2907 }
2908 }
2909
2910 if (result == null) {
2911 StringBundler query = new StringBundler(4);
2912
2913 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
2914
2915 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2916
2917 boolean bindName = false;
2918
2919 if (name == null) {
2920 query.append(_FINDER_COLUMN_G_N_NAME_1);
2921 }
2922 else if (name.equals(StringPool.BLANK)) {
2923 query.append(_FINDER_COLUMN_G_N_NAME_3);
2924 }
2925 else {
2926 bindName = true;
2927
2928 query.append(_FINDER_COLUMN_G_N_NAME_2);
2929 }
2930
2931 String sql = query.toString();
2932
2933 Session session = null;
2934
2935 try {
2936 session = openSession();
2937
2938 Query q = session.createQuery(sql);
2939
2940 QueryPos qPos = QueryPos.getInstance(q);
2941
2942 qPos.add(groupId);
2943
2944 if (bindName) {
2945 qPos.add(name);
2946 }
2947
2948 List<AssetVocabulary> list = q.list();
2949
2950 if (list.isEmpty()) {
2951 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2952 finderArgs, list);
2953 }
2954 else {
2955 AssetVocabulary assetVocabulary = list.get(0);
2956
2957 result = assetVocabulary;
2958
2959 cacheResult(assetVocabulary);
2960
2961 if ((assetVocabulary.getGroupId() != groupId) ||
2962 (assetVocabulary.getName() == null) ||
2963 !assetVocabulary.getName().equals(name)) {
2964 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2965 finderArgs, assetVocabulary);
2966 }
2967 }
2968 }
2969 catch (Exception e) {
2970 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
2971 finderArgs);
2972
2973 throw processException(e);
2974 }
2975 finally {
2976 closeSession(session);
2977 }
2978 }
2979
2980 if (result instanceof List<?>) {
2981 return null;
2982 }
2983 else {
2984 return (AssetVocabulary)result;
2985 }
2986 }
2987
2988
2996 @Override
2997 public AssetVocabulary removeByG_N(long groupId, String name)
2998 throws NoSuchVocabularyException, SystemException {
2999 AssetVocabulary assetVocabulary = findByG_N(groupId, name);
3000
3001 return remove(assetVocabulary);
3002 }
3003
3004
3012 @Override
3013 public int countByG_N(long groupId, String name) throws SystemException {
3014 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
3015
3016 Object[] finderArgs = new Object[] { groupId, name };
3017
3018 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3019 this);
3020
3021 if (count == null) {
3022 StringBundler query = new StringBundler(3);
3023
3024 query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
3025
3026 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
3027
3028 boolean bindName = false;
3029
3030 if (name == null) {
3031 query.append(_FINDER_COLUMN_G_N_NAME_1);
3032 }
3033 else if (name.equals(StringPool.BLANK)) {
3034 query.append(_FINDER_COLUMN_G_N_NAME_3);
3035 }
3036 else {
3037 bindName = true;
3038
3039 query.append(_FINDER_COLUMN_G_N_NAME_2);
3040 }
3041
3042 String sql = query.toString();
3043
3044 Session session = null;
3045
3046 try {
3047 session = openSession();
3048
3049 Query q = session.createQuery(sql);
3050
3051 QueryPos qPos = QueryPos.getInstance(q);
3052
3053 qPos.add(groupId);
3054
3055 if (bindName) {
3056 qPos.add(name);
3057 }
3058
3059 count = (Long)q.uniqueResult();
3060
3061 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3062 }
3063 catch (Exception e) {
3064 FinderCacheUtil.removeResult(finderPath, finderArgs);
3065
3066 throw processException(e);
3067 }
3068 finally {
3069 closeSession(session);
3070 }
3071 }
3072
3073 return count.intValue();
3074 }
3075
3076 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetVocabulary.groupId = ? AND ";
3077 private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetVocabulary.name IS NULL";
3078 private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetVocabulary.name = ?";
3079 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetVocabulary.name IS NULL OR assetVocabulary.name = '')";
3080
3081
3086 @Override
3087 public void cacheResult(AssetVocabulary assetVocabulary) {
3088 EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3089 AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
3090 assetVocabulary);
3091
3092 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
3093 new Object[] { assetVocabulary.getUuid(), assetVocabulary.getGroupId() },
3094 assetVocabulary);
3095
3096 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
3097 new Object[] { assetVocabulary.getGroupId(), assetVocabulary.getName() },
3098 assetVocabulary);
3099
3100 assetVocabulary.resetOriginalValues();
3101 }
3102
3103
3108 @Override
3109 public void cacheResult(List<AssetVocabulary> assetVocabularies) {
3110 for (AssetVocabulary assetVocabulary : assetVocabularies) {
3111 if (EntityCacheUtil.getResult(
3112 AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3113 AssetVocabularyImpl.class,
3114 assetVocabulary.getPrimaryKey()) == null) {
3115 cacheResult(assetVocabulary);
3116 }
3117 else {
3118 assetVocabulary.resetOriginalValues();
3119 }
3120 }
3121 }
3122
3123
3130 @Override
3131 public void clearCache() {
3132 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3133 CacheRegistryUtil.clear(AssetVocabularyImpl.class.getName());
3134 }
3135
3136 EntityCacheUtil.clearCache(AssetVocabularyImpl.class.getName());
3137
3138 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3139 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3141 }
3142
3143
3150 @Override
3151 public void clearCache(AssetVocabulary assetVocabulary) {
3152 EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3153 AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
3154
3155 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3157
3158 clearUniqueFindersCache(assetVocabulary);
3159 }
3160
3161 @Override
3162 public void clearCache(List<AssetVocabulary> assetVocabularies) {
3163 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3164 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3165
3166 for (AssetVocabulary assetVocabulary : assetVocabularies) {
3167 EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3168 AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
3169
3170 clearUniqueFindersCache(assetVocabulary);
3171 }
3172 }
3173
3174 protected void cacheUniqueFindersCache(AssetVocabulary assetVocabulary) {
3175 if (assetVocabulary.isNew()) {
3176 Object[] args = new Object[] {
3177 assetVocabulary.getUuid(), assetVocabulary.getGroupId()
3178 };
3179
3180 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3181 Long.valueOf(1));
3182 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3183 assetVocabulary);
3184
3185 args = new Object[] {
3186 assetVocabulary.getGroupId(), assetVocabulary.getName()
3187 };
3188
3189 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
3190 Long.valueOf(1));
3191 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
3192 assetVocabulary);
3193 }
3194 else {
3195 AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
3196
3197 if ((assetVocabularyModelImpl.getColumnBitmask() &
3198 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3199 Object[] args = new Object[] {
3200 assetVocabulary.getUuid(), assetVocabulary.getGroupId()
3201 };
3202
3203 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3204 Long.valueOf(1));
3205 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3206 assetVocabulary);
3207 }
3208
3209 if ((assetVocabularyModelImpl.getColumnBitmask() &
3210 FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
3211 Object[] args = new Object[] {
3212 assetVocabulary.getGroupId(), assetVocabulary.getName()
3213 };
3214
3215 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
3216 Long.valueOf(1));
3217 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
3218 assetVocabulary);
3219 }
3220 }
3221 }
3222
3223 protected void clearUniqueFindersCache(AssetVocabulary assetVocabulary) {
3224 AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
3225
3226 Object[] args = new Object[] {
3227 assetVocabulary.getUuid(), assetVocabulary.getGroupId()
3228 };
3229
3230 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3231 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3232
3233 if ((assetVocabularyModelImpl.getColumnBitmask() &
3234 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3235 args = new Object[] {
3236 assetVocabularyModelImpl.getOriginalUuid(),
3237 assetVocabularyModelImpl.getOriginalGroupId()
3238 };
3239
3240 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3241 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3242 }
3243
3244 args = new Object[] {
3245 assetVocabulary.getGroupId(), assetVocabulary.getName()
3246 };
3247
3248 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
3249 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
3250
3251 if ((assetVocabularyModelImpl.getColumnBitmask() &
3252 FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
3253 args = new Object[] {
3254 assetVocabularyModelImpl.getOriginalGroupId(),
3255 assetVocabularyModelImpl.getOriginalName()
3256 };
3257
3258 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
3259 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
3260 }
3261 }
3262
3263
3269 @Override
3270 public AssetVocabulary create(long vocabularyId) {
3271 AssetVocabulary assetVocabulary = new AssetVocabularyImpl();
3272
3273 assetVocabulary.setNew(true);
3274 assetVocabulary.setPrimaryKey(vocabularyId);
3275
3276 String uuid = PortalUUIDUtil.generate();
3277
3278 assetVocabulary.setUuid(uuid);
3279
3280 return assetVocabulary;
3281 }
3282
3283
3291 @Override
3292 public AssetVocabulary remove(long vocabularyId)
3293 throws NoSuchVocabularyException, SystemException {
3294 return remove((Serializable)vocabularyId);
3295 }
3296
3297
3305 @Override
3306 public AssetVocabulary remove(Serializable primaryKey)
3307 throws NoSuchVocabularyException, SystemException {
3308 Session session = null;
3309
3310 try {
3311 session = openSession();
3312
3313 AssetVocabulary assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
3314 primaryKey);
3315
3316 if (assetVocabulary == null) {
3317 if (_log.isWarnEnabled()) {
3318 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3319 }
3320
3321 throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3322 primaryKey);
3323 }
3324
3325 return remove(assetVocabulary);
3326 }
3327 catch (NoSuchVocabularyException nsee) {
3328 throw nsee;
3329 }
3330 catch (Exception e) {
3331 throw processException(e);
3332 }
3333 finally {
3334 closeSession(session);
3335 }
3336 }
3337
3338 @Override
3339 protected AssetVocabulary removeImpl(AssetVocabulary assetVocabulary)
3340 throws SystemException {
3341 assetVocabulary = toUnwrappedModel(assetVocabulary);
3342
3343 Session session = null;
3344
3345 try {
3346 session = openSession();
3347
3348 if (!session.contains(assetVocabulary)) {
3349 assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
3350 assetVocabulary.getPrimaryKeyObj());
3351 }
3352
3353 if (assetVocabulary != null) {
3354 session.delete(assetVocabulary);
3355 }
3356 }
3357 catch (Exception e) {
3358 throw processException(e);
3359 }
3360 finally {
3361 closeSession(session);
3362 }
3363
3364 if (assetVocabulary != null) {
3365 clearCache(assetVocabulary);
3366 }
3367
3368 return assetVocabulary;
3369 }
3370
3371 @Override
3372 public AssetVocabulary updateImpl(
3373 com.liferay.portlet.asset.model.AssetVocabulary assetVocabulary)
3374 throws SystemException {
3375 assetVocabulary = toUnwrappedModel(assetVocabulary);
3376
3377 boolean isNew = assetVocabulary.isNew();
3378
3379 AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
3380
3381 if (Validator.isNull(assetVocabulary.getUuid())) {
3382 String uuid = PortalUUIDUtil.generate();
3383
3384 assetVocabulary.setUuid(uuid);
3385 }
3386
3387 Session session = null;
3388
3389 try {
3390 session = openSession();
3391
3392 if (assetVocabulary.isNew()) {
3393 session.save(assetVocabulary);
3394
3395 assetVocabulary.setNew(false);
3396 }
3397 else {
3398 session.merge(assetVocabulary);
3399 }
3400 }
3401 catch (Exception e) {
3402 throw processException(e);
3403 }
3404 finally {
3405 closeSession(session);
3406 }
3407
3408 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3409
3410 if (isNew || !AssetVocabularyModelImpl.COLUMN_BITMASK_ENABLED) {
3411 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3412 }
3413
3414 else {
3415 if ((assetVocabularyModelImpl.getColumnBitmask() &
3416 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
3417 Object[] args = new Object[] {
3418 assetVocabularyModelImpl.getOriginalUuid()
3419 };
3420
3421 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3422 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3423 args);
3424
3425 args = new Object[] { assetVocabularyModelImpl.getUuid() };
3426
3427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3428 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3429 args);
3430 }
3431
3432 if ((assetVocabularyModelImpl.getColumnBitmask() &
3433 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
3434 Object[] args = new Object[] {
3435 assetVocabularyModelImpl.getOriginalUuid(),
3436 assetVocabularyModelImpl.getOriginalCompanyId()
3437 };
3438
3439 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3440 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3441 args);
3442
3443 args = new Object[] {
3444 assetVocabularyModelImpl.getUuid(),
3445 assetVocabularyModelImpl.getCompanyId()
3446 };
3447
3448 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3449 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3450 args);
3451 }
3452
3453 if ((assetVocabularyModelImpl.getColumnBitmask() &
3454 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3455 Object[] args = new Object[] {
3456 assetVocabularyModelImpl.getOriginalGroupId()
3457 };
3458
3459 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3460 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3461 args);
3462
3463 args = new Object[] { assetVocabularyModelImpl.getGroupId() };
3464
3465 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3466 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3467 args);
3468 }
3469
3470 if ((assetVocabularyModelImpl.getColumnBitmask() &
3471 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
3472 Object[] args = new Object[] {
3473 assetVocabularyModelImpl.getOriginalCompanyId()
3474 };
3475
3476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3477 args);
3478 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3479 args);
3480
3481 args = new Object[] { assetVocabularyModelImpl.getCompanyId() };
3482
3483 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3484 args);
3485 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3486 args);
3487 }
3488 }
3489
3490 EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3491 AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
3492 assetVocabulary);
3493
3494 clearUniqueFindersCache(assetVocabulary);
3495 cacheUniqueFindersCache(assetVocabulary);
3496
3497 return assetVocabulary;
3498 }
3499
3500 protected AssetVocabulary toUnwrappedModel(AssetVocabulary assetVocabulary) {
3501 if (assetVocabulary instanceof AssetVocabularyImpl) {
3502 return assetVocabulary;
3503 }
3504
3505 AssetVocabularyImpl assetVocabularyImpl = new AssetVocabularyImpl();
3506
3507 assetVocabularyImpl.setNew(assetVocabulary.isNew());
3508 assetVocabularyImpl.setPrimaryKey(assetVocabulary.getPrimaryKey());
3509
3510 assetVocabularyImpl.setUuid(assetVocabulary.getUuid());
3511 assetVocabularyImpl.setVocabularyId(assetVocabulary.getVocabularyId());
3512 assetVocabularyImpl.setGroupId(assetVocabulary.getGroupId());
3513 assetVocabularyImpl.setCompanyId(assetVocabulary.getCompanyId());
3514 assetVocabularyImpl.setUserId(assetVocabulary.getUserId());
3515 assetVocabularyImpl.setUserName(assetVocabulary.getUserName());
3516 assetVocabularyImpl.setCreateDate(assetVocabulary.getCreateDate());
3517 assetVocabularyImpl.setModifiedDate(assetVocabulary.getModifiedDate());
3518 assetVocabularyImpl.setName(assetVocabulary.getName());
3519 assetVocabularyImpl.setTitle(assetVocabulary.getTitle());
3520 assetVocabularyImpl.setDescription(assetVocabulary.getDescription());
3521 assetVocabularyImpl.setSettings(assetVocabulary.getSettings());
3522
3523 return assetVocabularyImpl;
3524 }
3525
3526
3534 @Override
3535 public AssetVocabulary findByPrimaryKey(Serializable primaryKey)
3536 throws NoSuchVocabularyException, SystemException {
3537 AssetVocabulary assetVocabulary = fetchByPrimaryKey(primaryKey);
3538
3539 if (assetVocabulary == null) {
3540 if (_log.isWarnEnabled()) {
3541 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3542 }
3543
3544 throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3545 primaryKey);
3546 }
3547
3548 return assetVocabulary;
3549 }
3550
3551
3559 @Override
3560 public AssetVocabulary findByPrimaryKey(long vocabularyId)
3561 throws NoSuchVocabularyException, SystemException {
3562 return findByPrimaryKey((Serializable)vocabularyId);
3563 }
3564
3565
3572 @Override
3573 public AssetVocabulary fetchByPrimaryKey(Serializable primaryKey)
3574 throws SystemException {
3575 AssetVocabulary assetVocabulary = (AssetVocabulary)EntityCacheUtil.getResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3576 AssetVocabularyImpl.class, primaryKey);
3577
3578 if (assetVocabulary == _nullAssetVocabulary) {
3579 return null;
3580 }
3581
3582 if (assetVocabulary == null) {
3583 Session session = null;
3584
3585 try {
3586 session = openSession();
3587
3588 assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
3589 primaryKey);
3590
3591 if (assetVocabulary != null) {
3592 cacheResult(assetVocabulary);
3593 }
3594 else {
3595 EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3596 AssetVocabularyImpl.class, primaryKey,
3597 _nullAssetVocabulary);
3598 }
3599 }
3600 catch (Exception e) {
3601 EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
3602 AssetVocabularyImpl.class, primaryKey);
3603
3604 throw processException(e);
3605 }
3606 finally {
3607 closeSession(session);
3608 }
3609 }
3610
3611 return assetVocabulary;
3612 }
3613
3614
3621 @Override
3622 public AssetVocabulary fetchByPrimaryKey(long vocabularyId)
3623 throws SystemException {
3624 return fetchByPrimaryKey((Serializable)vocabularyId);
3625 }
3626
3627
3633 @Override
3634 public List<AssetVocabulary> findAll() throws SystemException {
3635 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3636 }
3637
3638
3650 @Override
3651 public List<AssetVocabulary> findAll(int start, int end)
3652 throws SystemException {
3653 return findAll(start, end, null);
3654 }
3655
3656
3669 @Override
3670 public List<AssetVocabulary> findAll(int start, int end,
3671 OrderByComparator orderByComparator) throws SystemException {
3672 boolean pagination = true;
3673 FinderPath finderPath = null;
3674 Object[] finderArgs = null;
3675
3676 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3677 (orderByComparator == null)) {
3678 pagination = false;
3679 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3680 finderArgs = FINDER_ARGS_EMPTY;
3681 }
3682 else {
3683 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3684 finderArgs = new Object[] { start, end, orderByComparator };
3685 }
3686
3687 List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(finderPath,
3688 finderArgs, this);
3689
3690 if (list == null) {
3691 StringBundler query = null;
3692 String sql = null;
3693
3694 if (orderByComparator != null) {
3695 query = new StringBundler(2 +
3696 (orderByComparator.getOrderByFields().length * 3));
3697
3698 query.append(_SQL_SELECT_ASSETVOCABULARY);
3699
3700 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3701 orderByComparator);
3702
3703 sql = query.toString();
3704 }
3705 else {
3706 sql = _SQL_SELECT_ASSETVOCABULARY;
3707
3708 if (pagination) {
3709 sql = sql.concat(AssetVocabularyModelImpl.ORDER_BY_JPQL);
3710 }
3711 }
3712
3713 Session session = null;
3714
3715 try {
3716 session = openSession();
3717
3718 Query q = session.createQuery(sql);
3719
3720 if (!pagination) {
3721 list = (List<AssetVocabulary>)QueryUtil.list(q,
3722 getDialect(), start, end, false);
3723
3724 Collections.sort(list);
3725
3726 list = new UnmodifiableList<AssetVocabulary>(list);
3727 }
3728 else {
3729 list = (List<AssetVocabulary>)QueryUtil.list(q,
3730 getDialect(), start, end);
3731 }
3732
3733 cacheResult(list);
3734
3735 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3736 }
3737 catch (Exception e) {
3738 FinderCacheUtil.removeResult(finderPath, finderArgs);
3739
3740 throw processException(e);
3741 }
3742 finally {
3743 closeSession(session);
3744 }
3745 }
3746
3747 return list;
3748 }
3749
3750
3755 @Override
3756 public void removeAll() throws SystemException {
3757 for (AssetVocabulary assetVocabulary : findAll()) {
3758 remove(assetVocabulary);
3759 }
3760 }
3761
3762
3768 @Override
3769 public int countAll() throws SystemException {
3770 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3771 FINDER_ARGS_EMPTY, this);
3772
3773 if (count == null) {
3774 Session session = null;
3775
3776 try {
3777 session = openSession();
3778
3779 Query q = session.createQuery(_SQL_COUNT_ASSETVOCABULARY);
3780
3781 count = (Long)q.uniqueResult();
3782
3783 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3784 FINDER_ARGS_EMPTY, count);
3785 }
3786 catch (Exception e) {
3787 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3788 FINDER_ARGS_EMPTY);
3789
3790 throw processException(e);
3791 }
3792 finally {
3793 closeSession(session);
3794 }
3795 }
3796
3797 return count.intValue();
3798 }
3799
3800 @Override
3801 protected Set<String> getBadColumnNames() {
3802 return _badColumnNames;
3803 }
3804
3805
3808 public void afterPropertiesSet() {
3809 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3810 com.liferay.portal.util.PropsUtil.get(
3811 "value.object.listener.com.liferay.portlet.asset.model.AssetVocabulary")));
3812
3813 if (listenerClassNames.length > 0) {
3814 try {
3815 List<ModelListener<AssetVocabulary>> listenersList = new ArrayList<ModelListener<AssetVocabulary>>();
3816
3817 for (String listenerClassName : listenerClassNames) {
3818 listenersList.add((ModelListener<AssetVocabulary>)InstanceFactory.newInstance(
3819 getClassLoader(), listenerClassName));
3820 }
3821
3822 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3823 }
3824 catch (Exception e) {
3825 _log.error(e);
3826 }
3827 }
3828 }
3829
3830 public void destroy() {
3831 EntityCacheUtil.removeCache(AssetVocabularyImpl.class.getName());
3832 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3833 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3834 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3835 }
3836
3837 private static final String _SQL_SELECT_ASSETVOCABULARY = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary";
3838 private static final String _SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary WHERE ";
3839 private static final String _SQL_COUNT_ASSETVOCABULARY = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary";
3840 private static final String _SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary WHERE ";
3841 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetVocabulary.vocabularyId";
3842 private static final String _FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT DISTINCT {assetVocabulary.*} FROM AssetVocabulary assetVocabulary WHERE ";
3843 private static final String _FILTER_SQL_SELECT_ASSETVOCABULARY_NO_INLINE_DISTINCT_WHERE_1 =
3844 "SELECT {AssetVocabulary.*} FROM (SELECT DISTINCT assetVocabulary.vocabularyId FROM AssetVocabulary assetVocabulary WHERE ";
3845 private static final String _FILTER_SQL_SELECT_ASSETVOCABULARY_NO_INLINE_DISTINCT_WHERE_2 =
3846 ") TEMP_TABLE INNER JOIN AssetVocabulary ON TEMP_TABLE.vocabularyId = AssetVocabulary.vocabularyId";
3847 private static final String _FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(DISTINCT assetVocabulary.vocabularyId) AS COUNT_VALUE FROM AssetVocabulary assetVocabulary WHERE ";
3848 private static final String _FILTER_ENTITY_ALIAS = "assetVocabulary";
3849 private static final String _FILTER_ENTITY_TABLE = "AssetVocabulary";
3850 private static final String _ORDER_BY_ENTITY_ALIAS = "assetVocabulary.";
3851 private static final String _ORDER_BY_ENTITY_TABLE = "AssetVocabulary.";
3852 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetVocabulary exists with the primary key ";
3853 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetVocabulary exists with the key {";
3854 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3855 private static Log _log = LogFactoryUtil.getLog(AssetVocabularyPersistenceImpl.class);
3856 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3857 "uuid", "settings"
3858 });
3859 private static AssetVocabulary _nullAssetVocabulary = new AssetVocabularyImpl() {
3860 @Override
3861 public Object clone() {
3862 return this;
3863 }
3864
3865 @Override
3866 public CacheModel<AssetVocabulary> toCacheModel() {
3867 return _nullAssetVocabularyCacheModel;
3868 }
3869 };
3870
3871 private static CacheModel<AssetVocabulary> _nullAssetVocabularyCacheModel = new CacheModel<AssetVocabulary>() {
3872 @Override
3873 public AssetVocabulary toEntityModel() {
3874 return _nullAssetVocabulary;
3875 }
3876 };
3877 }