001
014
015 package com.liferay.portlet.asset.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderPath;
028 import com.liferay.portal.kernel.dao.orm.Query;
029 import com.liferay.portal.kernel.dao.orm.QueryPos;
030 import com.liferay.portal.kernel.dao.orm.QueryUtil;
031 import com.liferay.portal.kernel.dao.orm.SQLQuery;
032 import com.liferay.portal.kernel.dao.orm.Session;
033 import com.liferay.portal.kernel.exception.SystemException;
034 import com.liferay.portal.kernel.log.Log;
035 import com.liferay.portal.kernel.log.LogFactoryUtil;
036 import com.liferay.portal.kernel.util.GetterUtil;
037 import com.liferay.portal.kernel.util.InstanceFactory;
038 import com.liferay.portal.kernel.util.OrderByComparator;
039 import com.liferay.portal.kernel.util.SetUtil;
040 import com.liferay.portal.kernel.util.StringBundler;
041 import com.liferay.portal.kernel.util.StringPool;
042 import com.liferay.portal.kernel.util.StringUtil;
043 import com.liferay.portal.model.CacheModel;
044 import com.liferay.portal.model.ModelListener;
045 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046 import com.liferay.portal.service.persistence.BatchSessionUtil;
047 import com.liferay.portal.service.persistence.ResourcePersistence;
048 import com.liferay.portal.service.persistence.UserPersistence;
049 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050
051 import com.liferay.portlet.asset.NoSuchTagException;
052 import com.liferay.portlet.asset.model.AssetTag;
053 import com.liferay.portlet.asset.model.impl.AssetTagImpl;
054 import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
055
056 import java.io.Serializable;
057
058 import java.util.ArrayList;
059 import java.util.Collections;
060 import java.util.List;
061 import java.util.Set;
062
063
075 public class AssetTagPersistenceImpl extends BasePersistenceImpl<AssetTag>
076 implements AssetTagPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = AssetTagImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
088 AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
090 new String[] {
091 Long.class.getName(),
092
093 "java.lang.Integer", "java.lang.Integer",
094 "com.liferay.portal.kernel.util.OrderByComparator"
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
097 new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
098 AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
100 new String[] { Long.class.getName() },
101 AssetTagModelImpl.GROUPID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
103 AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
105 new String[] { Long.class.getName() });
106 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
107 AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
109 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
110 AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
111 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
113 AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
115
116
121 public void cacheResult(AssetTag assetTag) {
122 EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
123 AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
124
125 assetTag.resetOriginalValues();
126 }
127
128
133 public void cacheResult(List<AssetTag> assetTags) {
134 for (AssetTag assetTag : assetTags) {
135 if (EntityCacheUtil.getResult(
136 AssetTagModelImpl.ENTITY_CACHE_ENABLED,
137 AssetTagImpl.class, assetTag.getPrimaryKey()) == null) {
138 cacheResult(assetTag);
139 }
140 else {
141 assetTag.resetOriginalValues();
142 }
143 }
144 }
145
146
153 @Override
154 public void clearCache() {
155 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
156 CacheRegistryUtil.clear(AssetTagImpl.class.getName());
157 }
158
159 EntityCacheUtil.clearCache(AssetTagImpl.class.getName());
160
161 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
162 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
163 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
164 }
165
166
173 @Override
174 public void clearCache(AssetTag assetTag) {
175 EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
176 AssetTagImpl.class, assetTag.getPrimaryKey());
177
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
180 }
181
182
188 public AssetTag create(long tagId) {
189 AssetTag assetTag = new AssetTagImpl();
190
191 assetTag.setNew(true);
192 assetTag.setPrimaryKey(tagId);
193
194 return assetTag;
195 }
196
197
205 @Override
206 public AssetTag remove(Serializable primaryKey)
207 throws NoSuchModelException, SystemException {
208 return remove(((Long)primaryKey).longValue());
209 }
210
211
219 public AssetTag remove(long tagId)
220 throws NoSuchTagException, SystemException {
221 Session session = null;
222
223 try {
224 session = openSession();
225
226 AssetTag assetTag = (AssetTag)session.get(AssetTagImpl.class,
227 Long.valueOf(tagId));
228
229 if (assetTag == null) {
230 if (_log.isWarnEnabled()) {
231 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
232 }
233
234 throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
235 tagId);
236 }
237
238 return assetTagPersistence.remove(assetTag);
239 }
240 catch (NoSuchTagException nsee) {
241 throw nsee;
242 }
243 catch (Exception e) {
244 throw processException(e);
245 }
246 finally {
247 closeSession(session);
248 }
249 }
250
251
258 @Override
259 public AssetTag remove(AssetTag assetTag) throws SystemException {
260 return super.remove(assetTag);
261 }
262
263 @Override
264 protected AssetTag removeImpl(AssetTag assetTag) throws SystemException {
265 assetTag = toUnwrappedModel(assetTag);
266
267 try {
268 clearAssetEntries.clear(assetTag.getPrimaryKey());
269 }
270 catch (Exception e) {
271 throw processException(e);
272 }
273 finally {
274 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
275 }
276
277 Session session = null;
278
279 try {
280 session = openSession();
281
282 BatchSessionUtil.delete(session, assetTag);
283 }
284 catch (Exception e) {
285 throw processException(e);
286 }
287 finally {
288 closeSession(session);
289 }
290
291 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
292 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
293
294 EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
295 AssetTagImpl.class, assetTag.getPrimaryKey());
296
297 return assetTag;
298 }
299
300 @Override
301 public AssetTag updateImpl(
302 com.liferay.portlet.asset.model.AssetTag assetTag, boolean merge)
303 throws SystemException {
304 assetTag = toUnwrappedModel(assetTag);
305
306 boolean isNew = assetTag.isNew();
307
308 AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
309
310 Session session = null;
311
312 try {
313 session = openSession();
314
315 BatchSessionUtil.update(session, assetTag, merge);
316
317 assetTag.setNew(false);
318 }
319 catch (Exception e) {
320 throw processException(e);
321 }
322 finally {
323 closeSession(session);
324 }
325
326 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
327
328 if (isNew || !AssetTagModelImpl.COLUMN_BITMASK_ENABLED) {
329 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
330 }
331
332 else {
333 if ((assetTagModelImpl.getColumnBitmask() &
334 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
335 Object[] args = new Object[] {
336 Long.valueOf(assetTagModelImpl.getOriginalGroupId())
337 };
338
339 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
340 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
341 args);
342
343 args = new Object[] { Long.valueOf(assetTagModelImpl.getGroupId()) };
344
345 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
346 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
347 args);
348 }
349 }
350
351 EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
352 AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
353
354 return assetTag;
355 }
356
357 protected AssetTag toUnwrappedModel(AssetTag assetTag) {
358 if (assetTag instanceof AssetTagImpl) {
359 return assetTag;
360 }
361
362 AssetTagImpl assetTagImpl = new AssetTagImpl();
363
364 assetTagImpl.setNew(assetTag.isNew());
365 assetTagImpl.setPrimaryKey(assetTag.getPrimaryKey());
366
367 assetTagImpl.setTagId(assetTag.getTagId());
368 assetTagImpl.setGroupId(assetTag.getGroupId());
369 assetTagImpl.setCompanyId(assetTag.getCompanyId());
370 assetTagImpl.setUserId(assetTag.getUserId());
371 assetTagImpl.setUserName(assetTag.getUserName());
372 assetTagImpl.setCreateDate(assetTag.getCreateDate());
373 assetTagImpl.setModifiedDate(assetTag.getModifiedDate());
374 assetTagImpl.setName(assetTag.getName());
375 assetTagImpl.setAssetCount(assetTag.getAssetCount());
376
377 return assetTagImpl;
378 }
379
380
388 @Override
389 public AssetTag findByPrimaryKey(Serializable primaryKey)
390 throws NoSuchModelException, SystemException {
391 return findByPrimaryKey(((Long)primaryKey).longValue());
392 }
393
394
402 public AssetTag findByPrimaryKey(long tagId)
403 throws NoSuchTagException, SystemException {
404 AssetTag assetTag = fetchByPrimaryKey(tagId);
405
406 if (assetTag == null) {
407 if (_log.isWarnEnabled()) {
408 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
409 }
410
411 throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
412 tagId);
413 }
414
415 return assetTag;
416 }
417
418
425 @Override
426 public AssetTag fetchByPrimaryKey(Serializable primaryKey)
427 throws SystemException {
428 return fetchByPrimaryKey(((Long)primaryKey).longValue());
429 }
430
431
438 public AssetTag fetchByPrimaryKey(long tagId) throws SystemException {
439 AssetTag assetTag = (AssetTag)EntityCacheUtil.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
440 AssetTagImpl.class, tagId);
441
442 if (assetTag == _nullAssetTag) {
443 return null;
444 }
445
446 if (assetTag == null) {
447 Session session = null;
448
449 boolean hasException = false;
450
451 try {
452 session = openSession();
453
454 assetTag = (AssetTag)session.get(AssetTagImpl.class,
455 Long.valueOf(tagId));
456 }
457 catch (Exception e) {
458 hasException = true;
459
460 throw processException(e);
461 }
462 finally {
463 if (assetTag != null) {
464 cacheResult(assetTag);
465 }
466 else if (!hasException) {
467 EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
468 AssetTagImpl.class, tagId, _nullAssetTag);
469 }
470
471 closeSession(session);
472 }
473 }
474
475 return assetTag;
476 }
477
478
485 public List<AssetTag> findByGroupId(long groupId) throws SystemException {
486 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
487 }
488
489
502 public List<AssetTag> findByGroupId(long groupId, int start, int end)
503 throws SystemException {
504 return findByGroupId(groupId, start, end, null);
505 }
506
507
521 public List<AssetTag> findByGroupId(long groupId, int start, int end,
522 OrderByComparator orderByComparator) throws SystemException {
523 FinderPath finderPath = null;
524 Object[] finderArgs = null;
525
526 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
527 (orderByComparator == null)) {
528 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
529 finderArgs = new Object[] { groupId };
530 }
531 else {
532 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
533 finderArgs = new Object[] { groupId, start, end, orderByComparator };
534 }
535
536 List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
537 finderArgs, this);
538
539 if (list == null) {
540 StringBundler query = null;
541
542 if (orderByComparator != null) {
543 query = new StringBundler(3 +
544 (orderByComparator.getOrderByFields().length * 3));
545 }
546 else {
547 query = new StringBundler(3);
548 }
549
550 query.append(_SQL_SELECT_ASSETTAG_WHERE);
551
552 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
553
554 if (orderByComparator != null) {
555 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
556 orderByComparator);
557 }
558
559 else {
560 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
561 }
562
563 String sql = query.toString();
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 Query q = session.createQuery(sql);
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 qPos.add(groupId);
575
576 list = (List<AssetTag>)QueryUtil.list(q, getDialect(), start,
577 end);
578 }
579 catch (Exception e) {
580 throw processException(e);
581 }
582 finally {
583 if (list == null) {
584 FinderCacheUtil.removeResult(finderPath, finderArgs);
585 }
586 else {
587 cacheResult(list);
588
589 FinderCacheUtil.putResult(finderPath, finderArgs, list);
590 }
591
592 closeSession(session);
593 }
594 }
595
596 return list;
597 }
598
599
612 public AssetTag findByGroupId_First(long groupId,
613 OrderByComparator orderByComparator)
614 throws NoSuchTagException, SystemException {
615 List<AssetTag> list = findByGroupId(groupId, 0, 1, orderByComparator);
616
617 if (list.isEmpty()) {
618 StringBundler msg = new StringBundler(4);
619
620 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
621
622 msg.append("groupId=");
623 msg.append(groupId);
624
625 msg.append(StringPool.CLOSE_CURLY_BRACE);
626
627 throw new NoSuchTagException(msg.toString());
628 }
629 else {
630 return list.get(0);
631 }
632 }
633
634
647 public AssetTag findByGroupId_Last(long groupId,
648 OrderByComparator orderByComparator)
649 throws NoSuchTagException, SystemException {
650 int count = countByGroupId(groupId);
651
652 List<AssetTag> list = findByGroupId(groupId, count - 1, count,
653 orderByComparator);
654
655 if (list.isEmpty()) {
656 StringBundler msg = new StringBundler(4);
657
658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
659
660 msg.append("groupId=");
661 msg.append(groupId);
662
663 msg.append(StringPool.CLOSE_CURLY_BRACE);
664
665 throw new NoSuchTagException(msg.toString());
666 }
667 else {
668 return list.get(0);
669 }
670 }
671
672
686 public AssetTag[] findByGroupId_PrevAndNext(long tagId, long groupId,
687 OrderByComparator orderByComparator)
688 throws NoSuchTagException, SystemException {
689 AssetTag assetTag = findByPrimaryKey(tagId);
690
691 Session session = null;
692
693 try {
694 session = openSession();
695
696 AssetTag[] array = new AssetTagImpl[3];
697
698 array[0] = getByGroupId_PrevAndNext(session, assetTag, groupId,
699 orderByComparator, true);
700
701 array[1] = assetTag;
702
703 array[2] = getByGroupId_PrevAndNext(session, assetTag, groupId,
704 orderByComparator, false);
705
706 return array;
707 }
708 catch (Exception e) {
709 throw processException(e);
710 }
711 finally {
712 closeSession(session);
713 }
714 }
715
716 protected AssetTag getByGroupId_PrevAndNext(Session session,
717 AssetTag assetTag, long groupId, OrderByComparator orderByComparator,
718 boolean previous) {
719 StringBundler query = null;
720
721 if (orderByComparator != null) {
722 query = new StringBundler(6 +
723 (orderByComparator.getOrderByFields().length * 6));
724 }
725 else {
726 query = new StringBundler(3);
727 }
728
729 query.append(_SQL_SELECT_ASSETTAG_WHERE);
730
731 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
732
733 if (orderByComparator != null) {
734 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
735
736 if (orderByConditionFields.length > 0) {
737 query.append(WHERE_AND);
738 }
739
740 for (int i = 0; i < orderByConditionFields.length; i++) {
741 query.append(_ORDER_BY_ENTITY_ALIAS);
742 query.append(orderByConditionFields[i]);
743
744 if ((i + 1) < orderByConditionFields.length) {
745 if (orderByComparator.isAscending() ^ previous) {
746 query.append(WHERE_GREATER_THAN_HAS_NEXT);
747 }
748 else {
749 query.append(WHERE_LESSER_THAN_HAS_NEXT);
750 }
751 }
752 else {
753 if (orderByComparator.isAscending() ^ previous) {
754 query.append(WHERE_GREATER_THAN);
755 }
756 else {
757 query.append(WHERE_LESSER_THAN);
758 }
759 }
760 }
761
762 query.append(ORDER_BY_CLAUSE);
763
764 String[] orderByFields = orderByComparator.getOrderByFields();
765
766 for (int i = 0; i < orderByFields.length; i++) {
767 query.append(_ORDER_BY_ENTITY_ALIAS);
768 query.append(orderByFields[i]);
769
770 if ((i + 1) < orderByFields.length) {
771 if (orderByComparator.isAscending() ^ previous) {
772 query.append(ORDER_BY_ASC_HAS_NEXT);
773 }
774 else {
775 query.append(ORDER_BY_DESC_HAS_NEXT);
776 }
777 }
778 else {
779 if (orderByComparator.isAscending() ^ previous) {
780 query.append(ORDER_BY_ASC);
781 }
782 else {
783 query.append(ORDER_BY_DESC);
784 }
785 }
786 }
787 }
788
789 else {
790 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
791 }
792
793 String sql = query.toString();
794
795 Query q = session.createQuery(sql);
796
797 q.setFirstResult(0);
798 q.setMaxResults(2);
799
800 QueryPos qPos = QueryPos.getInstance(q);
801
802 qPos.add(groupId);
803
804 if (orderByComparator != null) {
805 Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
806
807 for (Object value : values) {
808 qPos.add(value);
809 }
810 }
811
812 List<AssetTag> list = q.list();
813
814 if (list.size() == 2) {
815 return list.get(1);
816 }
817 else {
818 return null;
819 }
820 }
821
822
829 public List<AssetTag> filterFindByGroupId(long groupId)
830 throws SystemException {
831 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
832 QueryUtil.ALL_POS, null);
833 }
834
835
848 public List<AssetTag> filterFindByGroupId(long groupId, int start, int end)
849 throws SystemException {
850 return filterFindByGroupId(groupId, start, end, null);
851 }
852
853
867 public List<AssetTag> filterFindByGroupId(long groupId, int start, int end,
868 OrderByComparator orderByComparator) throws SystemException {
869 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
870 return findByGroupId(groupId, start, end, orderByComparator);
871 }
872
873 StringBundler query = null;
874
875 if (orderByComparator != null) {
876 query = new StringBundler(3 +
877 (orderByComparator.getOrderByFields().length * 3));
878 }
879 else {
880 query = new StringBundler(3);
881 }
882
883 if (getDB().isSupportsInlineDistinct()) {
884 query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
885 }
886 else {
887 query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
888 }
889
890 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
891
892 if (!getDB().isSupportsInlineDistinct()) {
893 query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
894 }
895
896 if (orderByComparator != null) {
897 if (getDB().isSupportsInlineDistinct()) {
898 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
899 orderByComparator);
900 }
901 else {
902 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
903 orderByComparator);
904 }
905 }
906
907 else {
908 if (getDB().isSupportsInlineDistinct()) {
909 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
910 }
911 else {
912 query.append(AssetTagModelImpl.ORDER_BY_SQL);
913 }
914 }
915
916 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
917 AssetTag.class.getName(),
918 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
919
920 Session session = null;
921
922 try {
923 session = openSession();
924
925 SQLQuery q = session.createSQLQuery(sql);
926
927 if (getDB().isSupportsInlineDistinct()) {
928 q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
929 }
930 else {
931 q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
932 }
933
934 QueryPos qPos = QueryPos.getInstance(q);
935
936 qPos.add(groupId);
937
938 return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
939 }
940 catch (Exception e) {
941 throw processException(e);
942 }
943 finally {
944 closeSession(session);
945 }
946 }
947
948
958 public AssetTag[] filterFindByGroupId_PrevAndNext(long tagId, long groupId,
959 OrderByComparator orderByComparator)
960 throws NoSuchTagException, SystemException {
961 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
962 return findByGroupId_PrevAndNext(tagId, groupId, orderByComparator);
963 }
964
965 AssetTag assetTag = findByPrimaryKey(tagId);
966
967 Session session = null;
968
969 try {
970 session = openSession();
971
972 AssetTag[] array = new AssetTagImpl[3];
973
974 array[0] = filterGetByGroupId_PrevAndNext(session, assetTag,
975 groupId, orderByComparator, true);
976
977 array[1] = assetTag;
978
979 array[2] = filterGetByGroupId_PrevAndNext(session, assetTag,
980 groupId, orderByComparator, false);
981
982 return array;
983 }
984 catch (Exception e) {
985 throw processException(e);
986 }
987 finally {
988 closeSession(session);
989 }
990 }
991
992 protected AssetTag filterGetByGroupId_PrevAndNext(Session session,
993 AssetTag assetTag, long groupId, OrderByComparator orderByComparator,
994 boolean previous) {
995 StringBundler query = null;
996
997 if (orderByComparator != null) {
998 query = new StringBundler(6 +
999 (orderByComparator.getOrderByFields().length * 6));
1000 }
1001 else {
1002 query = new StringBundler(3);
1003 }
1004
1005 if (getDB().isSupportsInlineDistinct()) {
1006 query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
1007 }
1008 else {
1009 query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
1010 }
1011
1012 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1013
1014 if (!getDB().isSupportsInlineDistinct()) {
1015 query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
1016 }
1017
1018 if (orderByComparator != null) {
1019 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1020
1021 if (orderByConditionFields.length > 0) {
1022 query.append(WHERE_AND);
1023 }
1024
1025 for (int i = 0; i < orderByConditionFields.length; i++) {
1026 if (getDB().isSupportsInlineDistinct()) {
1027 query.append(_ORDER_BY_ENTITY_ALIAS);
1028 }
1029 else {
1030 query.append(_ORDER_BY_ENTITY_TABLE);
1031 }
1032
1033 query.append(orderByConditionFields[i]);
1034
1035 if ((i + 1) < orderByConditionFields.length) {
1036 if (orderByComparator.isAscending() ^ previous) {
1037 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1038 }
1039 else {
1040 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1041 }
1042 }
1043 else {
1044 if (orderByComparator.isAscending() ^ previous) {
1045 query.append(WHERE_GREATER_THAN);
1046 }
1047 else {
1048 query.append(WHERE_LESSER_THAN);
1049 }
1050 }
1051 }
1052
1053 query.append(ORDER_BY_CLAUSE);
1054
1055 String[] orderByFields = orderByComparator.getOrderByFields();
1056
1057 for (int i = 0; i < orderByFields.length; i++) {
1058 if (getDB().isSupportsInlineDistinct()) {
1059 query.append(_ORDER_BY_ENTITY_ALIAS);
1060 }
1061 else {
1062 query.append(_ORDER_BY_ENTITY_TABLE);
1063 }
1064
1065 query.append(orderByFields[i]);
1066
1067 if ((i + 1) < orderByFields.length) {
1068 if (orderByComparator.isAscending() ^ previous) {
1069 query.append(ORDER_BY_ASC_HAS_NEXT);
1070 }
1071 else {
1072 query.append(ORDER_BY_DESC_HAS_NEXT);
1073 }
1074 }
1075 else {
1076 if (orderByComparator.isAscending() ^ previous) {
1077 query.append(ORDER_BY_ASC);
1078 }
1079 else {
1080 query.append(ORDER_BY_DESC);
1081 }
1082 }
1083 }
1084 }
1085
1086 else {
1087 if (getDB().isSupportsInlineDistinct()) {
1088 query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1089 }
1090 else {
1091 query.append(AssetTagModelImpl.ORDER_BY_SQL);
1092 }
1093 }
1094
1095 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1096 AssetTag.class.getName(),
1097 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1098
1099 SQLQuery q = session.createSQLQuery(sql);
1100
1101 q.setFirstResult(0);
1102 q.setMaxResults(2);
1103
1104 if (getDB().isSupportsInlineDistinct()) {
1105 q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
1106 }
1107 else {
1108 q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
1109 }
1110
1111 QueryPos qPos = QueryPos.getInstance(q);
1112
1113 qPos.add(groupId);
1114
1115 if (orderByComparator != null) {
1116 Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
1117
1118 for (Object value : values) {
1119 qPos.add(value);
1120 }
1121 }
1122
1123 List<AssetTag> list = q.list();
1124
1125 if (list.size() == 2) {
1126 return list.get(1);
1127 }
1128 else {
1129 return null;
1130 }
1131 }
1132
1133
1139 public List<AssetTag> findAll() throws SystemException {
1140 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1141 }
1142
1143
1155 public List<AssetTag> findAll(int start, int end) throws SystemException {
1156 return findAll(start, end, null);
1157 }
1158
1159
1172 public List<AssetTag> findAll(int start, int end,
1173 OrderByComparator orderByComparator) throws SystemException {
1174 FinderPath finderPath = null;
1175 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1176
1177 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1178 (orderByComparator == null)) {
1179 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1180 finderArgs = FINDER_ARGS_EMPTY;
1181 }
1182 else {
1183 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1184 finderArgs = new Object[] { start, end, orderByComparator };
1185 }
1186
1187 List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
1188 finderArgs, this);
1189
1190 if (list == null) {
1191 StringBundler query = null;
1192 String sql = null;
1193
1194 if (orderByComparator != null) {
1195 query = new StringBundler(2 +
1196 (orderByComparator.getOrderByFields().length * 3));
1197
1198 query.append(_SQL_SELECT_ASSETTAG);
1199
1200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1201 orderByComparator);
1202
1203 sql = query.toString();
1204 }
1205 else {
1206 sql = _SQL_SELECT_ASSETTAG.concat(AssetTagModelImpl.ORDER_BY_JPQL);
1207 }
1208
1209 Session session = null;
1210
1211 try {
1212 session = openSession();
1213
1214 Query q = session.createQuery(sql);
1215
1216 if (orderByComparator == null) {
1217 list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1218 start, end, false);
1219
1220 Collections.sort(list);
1221 }
1222 else {
1223 list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1224 start, end);
1225 }
1226 }
1227 catch (Exception e) {
1228 throw processException(e);
1229 }
1230 finally {
1231 if (list == null) {
1232 FinderCacheUtil.removeResult(finderPath, finderArgs);
1233 }
1234 else {
1235 cacheResult(list);
1236
1237 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1238 }
1239
1240 closeSession(session);
1241 }
1242 }
1243
1244 return list;
1245 }
1246
1247
1253 public void removeByGroupId(long groupId) throws SystemException {
1254 for (AssetTag assetTag : findByGroupId(groupId)) {
1255 assetTagPersistence.remove(assetTag);
1256 }
1257 }
1258
1259
1264 public void removeAll() throws SystemException {
1265 for (AssetTag assetTag : findAll()) {
1266 assetTagPersistence.remove(assetTag);
1267 }
1268 }
1269
1270
1277 public int countByGroupId(long groupId) throws SystemException {
1278 Object[] finderArgs = new Object[] { groupId };
1279
1280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1281 finderArgs, this);
1282
1283 if (count == null) {
1284 StringBundler query = new StringBundler(2);
1285
1286 query.append(_SQL_COUNT_ASSETTAG_WHERE);
1287
1288 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1289
1290 String sql = query.toString();
1291
1292 Session session = null;
1293
1294 try {
1295 session = openSession();
1296
1297 Query q = session.createQuery(sql);
1298
1299 QueryPos qPos = QueryPos.getInstance(q);
1300
1301 qPos.add(groupId);
1302
1303 count = (Long)q.uniqueResult();
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 if (count == null) {
1310 count = Long.valueOf(0);
1311 }
1312
1313 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1314 finderArgs, count);
1315
1316 closeSession(session);
1317 }
1318 }
1319
1320 return count.intValue();
1321 }
1322
1323
1330 public int filterCountByGroupId(long groupId) throws SystemException {
1331 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1332 return countByGroupId(groupId);
1333 }
1334
1335 StringBundler query = new StringBundler(2);
1336
1337 query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
1338
1339 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1340
1341 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1342 AssetTag.class.getName(),
1343 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1344
1345 Session session = null;
1346
1347 try {
1348 session = openSession();
1349
1350 SQLQuery q = session.createSQLQuery(sql);
1351
1352 q.addScalar(COUNT_COLUMN_NAME,
1353 com.liferay.portal.kernel.dao.orm.Type.LONG);
1354
1355 QueryPos qPos = QueryPos.getInstance(q);
1356
1357 qPos.add(groupId);
1358
1359 Long count = (Long)q.uniqueResult();
1360
1361 return count.intValue();
1362 }
1363 catch (Exception e) {
1364 throw processException(e);
1365 }
1366 finally {
1367 closeSession(session);
1368 }
1369 }
1370
1371
1377 public int countAll() throws SystemException {
1378 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1379 FINDER_ARGS_EMPTY, this);
1380
1381 if (count == null) {
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 Query q = session.createQuery(_SQL_COUNT_ASSETTAG);
1388
1389 count = (Long)q.uniqueResult();
1390 }
1391 catch (Exception e) {
1392 throw processException(e);
1393 }
1394 finally {
1395 if (count == null) {
1396 count = Long.valueOf(0);
1397 }
1398
1399 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1400 FINDER_ARGS_EMPTY, count);
1401
1402 closeSession(session);
1403 }
1404 }
1405
1406 return count.intValue();
1407 }
1408
1409
1416 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
1417 long pk) throws SystemException {
1418 return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1419 }
1420
1421
1434 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
1435 long pk, int start, int end) throws SystemException {
1436 return getAssetEntries(pk, start, end, null);
1437 }
1438
1439 public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1440 AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1441 com.liferay.portlet.asset.model.impl.AssetEntryImpl.class,
1442 AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1443 "getAssetEntries",
1444 new String[] {
1445 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1446 "com.liferay.portal.kernel.util.OrderByComparator"
1447 });
1448
1449
1463 public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
1464 long pk, int start, int end, OrderByComparator orderByComparator)
1465 throws SystemException {
1466 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
1467
1468 List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
1469 finderArgs, this);
1470
1471 if (list == null) {
1472 Session session = null;
1473
1474 try {
1475 session = openSession();
1476
1477 String sql = null;
1478
1479 if (orderByComparator != null) {
1480 sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
1481 .concat(orderByComparator.getOrderBy());
1482 }
1483 else {
1484 sql = _SQL_GETASSETENTRIES;
1485 }
1486
1487 SQLQuery q = session.createSQLQuery(sql);
1488
1489 q.addEntity("AssetEntry",
1490 com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
1491
1492 QueryPos qPos = QueryPos.getInstance(q);
1493
1494 qPos.add(pk);
1495
1496 list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
1497 getDialect(), start, end);
1498 }
1499 catch (Exception e) {
1500 throw processException(e);
1501 }
1502 finally {
1503 if (list == null) {
1504 FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES,
1505 finderArgs);
1506 }
1507 else {
1508 assetEntryPersistence.cacheResult(list);
1509
1510 FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
1511 finderArgs, list);
1512 }
1513
1514 closeSession(session);
1515 }
1516 }
1517
1518 return list;
1519 }
1520
1521 public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1522 AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1523 Long.class,
1524 AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1525 "getAssetEntriesSize", new String[] { Long.class.getName() });
1526
1527
1534 public int getAssetEntriesSize(long pk) throws SystemException {
1535 Object[] finderArgs = new Object[] { pk };
1536
1537 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
1538 finderArgs, this);
1539
1540 if (count == null) {
1541 Session session = null;
1542
1543 try {
1544 session = openSession();
1545
1546 SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
1547
1548 q.addScalar(COUNT_COLUMN_NAME,
1549 com.liferay.portal.kernel.dao.orm.Type.LONG);
1550
1551 QueryPos qPos = QueryPos.getInstance(q);
1552
1553 qPos.add(pk);
1554
1555 count = (Long)q.uniqueResult();
1556 }
1557 catch (Exception e) {
1558 throw processException(e);
1559 }
1560 finally {
1561 if (count == null) {
1562 count = Long.valueOf(0);
1563 }
1564
1565 FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
1566 finderArgs, count);
1567
1568 closeSession(session);
1569 }
1570 }
1571
1572 return count.intValue();
1573 }
1574
1575 public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1576 AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1577 Boolean.class,
1578 AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1579 "containsAssetEntry",
1580 new String[] { Long.class.getName(), Long.class.getName() });
1581
1582
1590 public boolean containsAssetEntry(long pk, long assetEntryPK)
1591 throws SystemException {
1592 Object[] finderArgs = new Object[] { pk, assetEntryPK };
1593
1594 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
1595 finderArgs, this);
1596
1597 if (value == null) {
1598 try {
1599 value = Boolean.valueOf(containsAssetEntry.contains(pk,
1600 assetEntryPK));
1601 }
1602 catch (Exception e) {
1603 throw processException(e);
1604 }
1605 finally {
1606 if (value == null) {
1607 value = Boolean.FALSE;
1608 }
1609
1610 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
1611 finderArgs, value);
1612 }
1613 }
1614
1615 return value.booleanValue();
1616 }
1617
1618
1625 public boolean containsAssetEntries(long pk) throws SystemException {
1626 if (getAssetEntriesSize(pk) > 0) {
1627 return true;
1628 }
1629 else {
1630 return false;
1631 }
1632 }
1633
1634
1641 public void addAssetEntry(long pk, long assetEntryPK)
1642 throws SystemException {
1643 try {
1644 addAssetEntry.add(pk, assetEntryPK);
1645 }
1646 catch (Exception e) {
1647 throw processException(e);
1648 }
1649 finally {
1650 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1651 }
1652 }
1653
1654
1661 public void addAssetEntry(long pk,
1662 com.liferay.portlet.asset.model.AssetEntry assetEntry)
1663 throws SystemException {
1664 try {
1665 addAssetEntry.add(pk, assetEntry.getPrimaryKey());
1666 }
1667 catch (Exception e) {
1668 throw processException(e);
1669 }
1670 finally {
1671 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1672 }
1673 }
1674
1675
1682 public void addAssetEntries(long pk, long[] assetEntryPKs)
1683 throws SystemException {
1684 try {
1685 for (long assetEntryPK : assetEntryPKs) {
1686 addAssetEntry.add(pk, assetEntryPK);
1687 }
1688 }
1689 catch (Exception e) {
1690 throw processException(e);
1691 }
1692 finally {
1693 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1694 }
1695 }
1696
1697
1704 public void addAssetEntries(long pk,
1705 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1706 throws SystemException {
1707 try {
1708 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1709 addAssetEntry.add(pk, assetEntry.getPrimaryKey());
1710 }
1711 }
1712 catch (Exception e) {
1713 throw processException(e);
1714 }
1715 finally {
1716 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1717 }
1718 }
1719
1720
1726 public void clearAssetEntries(long pk) throws SystemException {
1727 try {
1728 clearAssetEntries.clear(pk);
1729 }
1730 catch (Exception e) {
1731 throw processException(e);
1732 }
1733 finally {
1734 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1735 }
1736 }
1737
1738
1745 public void removeAssetEntry(long pk, long assetEntryPK)
1746 throws SystemException {
1747 try {
1748 removeAssetEntry.remove(pk, assetEntryPK);
1749 }
1750 catch (Exception e) {
1751 throw processException(e);
1752 }
1753 finally {
1754 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1755 }
1756 }
1757
1758
1765 public void removeAssetEntry(long pk,
1766 com.liferay.portlet.asset.model.AssetEntry assetEntry)
1767 throws SystemException {
1768 try {
1769 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1770 }
1771 catch (Exception e) {
1772 throw processException(e);
1773 }
1774 finally {
1775 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1776 }
1777 }
1778
1779
1786 public void removeAssetEntries(long pk, long[] assetEntryPKs)
1787 throws SystemException {
1788 try {
1789 for (long assetEntryPK : assetEntryPKs) {
1790 removeAssetEntry.remove(pk, assetEntryPK);
1791 }
1792 }
1793 catch (Exception e) {
1794 throw processException(e);
1795 }
1796 finally {
1797 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1798 }
1799 }
1800
1801
1808 public void removeAssetEntries(long pk,
1809 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1810 throws SystemException {
1811 try {
1812 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1813 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1814 }
1815 }
1816 catch (Exception e) {
1817 throw processException(e);
1818 }
1819 finally {
1820 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1821 }
1822 }
1823
1824
1831 public void setAssetEntries(long pk, long[] assetEntryPKs)
1832 throws SystemException {
1833 try {
1834 Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
1835
1836 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
1837
1838 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1839 if (!assetEntryPKSet.remove(assetEntry.getPrimaryKey())) {
1840 removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1841 }
1842 }
1843
1844 for (Long assetEntryPK : assetEntryPKSet) {
1845 addAssetEntry.add(pk, assetEntryPK);
1846 }
1847 }
1848 catch (Exception e) {
1849 throw processException(e);
1850 }
1851 finally {
1852 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1853 }
1854 }
1855
1856
1863 public void setAssetEntries(long pk,
1864 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1865 throws SystemException {
1866 try {
1867 long[] assetEntryPKs = new long[assetEntries.size()];
1868
1869 for (int i = 0; i < assetEntries.size(); i++) {
1870 com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
1871
1872 assetEntryPKs[i] = assetEntry.getPrimaryKey();
1873 }
1874
1875 setAssetEntries(pk, assetEntryPKs);
1876 }
1877 catch (Exception e) {
1878 throw processException(e);
1879 }
1880 finally {
1881 FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1882 }
1883 }
1884
1885
1888 public void afterPropertiesSet() {
1889 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1890 com.liferay.portal.util.PropsUtil.get(
1891 "value.object.listener.com.liferay.portlet.asset.model.AssetTag")));
1892
1893 if (listenerClassNames.length > 0) {
1894 try {
1895 List<ModelListener<AssetTag>> listenersList = new ArrayList<ModelListener<AssetTag>>();
1896
1897 for (String listenerClassName : listenerClassNames) {
1898 listenersList.add((ModelListener<AssetTag>)InstanceFactory.newInstance(
1899 listenerClassName));
1900 }
1901
1902 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1903 }
1904 catch (Exception e) {
1905 _log.error(e);
1906 }
1907 }
1908
1909 containsAssetEntry = new ContainsAssetEntry(this);
1910
1911 addAssetEntry = new AddAssetEntry(this);
1912 clearAssetEntries = new ClearAssetEntries(this);
1913 removeAssetEntry = new RemoveAssetEntry(this);
1914 }
1915
1916 public void destroy() {
1917 EntityCacheUtil.removeCache(AssetTagImpl.class.getName());
1918 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1919 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1920 }
1921
1922 @BeanReference(type = AssetCategoryPersistence.class)
1923 protected AssetCategoryPersistence assetCategoryPersistence;
1924 @BeanReference(type = AssetCategoryPropertyPersistence.class)
1925 protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1926 @BeanReference(type = AssetEntryPersistence.class)
1927 protected AssetEntryPersistence assetEntryPersistence;
1928 @BeanReference(type = AssetLinkPersistence.class)
1929 protected AssetLinkPersistence assetLinkPersistence;
1930 @BeanReference(type = AssetTagPersistence.class)
1931 protected AssetTagPersistence assetTagPersistence;
1932 @BeanReference(type = AssetTagPropertyPersistence.class)
1933 protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1934 @BeanReference(type = AssetTagStatsPersistence.class)
1935 protected AssetTagStatsPersistence assetTagStatsPersistence;
1936 @BeanReference(type = AssetVocabularyPersistence.class)
1937 protected AssetVocabularyPersistence assetVocabularyPersistence;
1938 @BeanReference(type = ResourcePersistence.class)
1939 protected ResourcePersistence resourcePersistence;
1940 @BeanReference(type = UserPersistence.class)
1941 protected UserPersistence userPersistence;
1942 protected ContainsAssetEntry containsAssetEntry;
1943 protected AddAssetEntry addAssetEntry;
1944 protected ClearAssetEntries clearAssetEntries;
1945 protected RemoveAssetEntry removeAssetEntry;
1946
1947 protected class ContainsAssetEntry {
1948 protected ContainsAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1949 super();
1950
1951 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1952 _SQL_CONTAINSASSETENTRY,
1953 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
1954 RowMapper.COUNT);
1955 }
1956
1957 protected boolean contains(long tagId, long entryId) {
1958 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1959 new Long(tagId), new Long(entryId)
1960 });
1961
1962 if (results.size() > 0) {
1963 Integer count = results.get(0);
1964
1965 if (count.intValue() > 0) {
1966 return true;
1967 }
1968 }
1969
1970 return false;
1971 }
1972
1973 private MappingSqlQuery<Integer> _mappingSqlQuery;
1974 }
1975
1976 protected class AddAssetEntry {
1977 protected AddAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1978 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1979 "INSERT INTO AssetEntries_AssetTags (tagId, entryId) VALUES (?, ?)",
1980 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
1981 _persistenceImpl = persistenceImpl;
1982 }
1983
1984 protected void add(long tagId, long entryId) throws SystemException {
1985 if (!_persistenceImpl.containsAssetEntry.contains(tagId, entryId)) {
1986 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1987 assetEntryPersistence.getListeners();
1988
1989 for (ModelListener<AssetTag> listener : listeners) {
1990 listener.onBeforeAddAssociation(tagId,
1991 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1992 entryId);
1993 }
1994
1995 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1996 listener.onBeforeAddAssociation(entryId,
1997 AssetTag.class.getName(), tagId);
1998 }
1999
2000 _sqlUpdate.update(new Object[] {
2001 new Long(tagId), new Long(entryId)
2002 });
2003
2004 for (ModelListener<AssetTag> listener : listeners) {
2005 listener.onAfterAddAssociation(tagId,
2006 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2007 entryId);
2008 }
2009
2010 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2011 listener.onAfterAddAssociation(entryId,
2012 AssetTag.class.getName(), tagId);
2013 }
2014 }
2015 }
2016
2017 private SqlUpdate _sqlUpdate;
2018 private AssetTagPersistenceImpl _persistenceImpl;
2019 }
2020
2021 protected class ClearAssetEntries {
2022 protected ClearAssetEntries(AssetTagPersistenceImpl persistenceImpl) {
2023 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2024 "DELETE FROM AssetEntries_AssetTags WHERE tagId = ?",
2025 new int[] { java.sql.Types.BIGINT });
2026 }
2027
2028 protected void clear(long tagId) throws SystemException {
2029 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
2030 assetEntryPersistence.getListeners();
2031
2032 List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
2033
2034 if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
2035 assetEntries = getAssetEntries(tagId);
2036
2037 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2038 for (ModelListener<AssetTag> listener : listeners) {
2039 listener.onBeforeRemoveAssociation(tagId,
2040 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2041 assetEntry.getPrimaryKey());
2042 }
2043
2044 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2045 listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
2046 AssetTag.class.getName(), tagId);
2047 }
2048 }
2049 }
2050
2051 _sqlUpdate.update(new Object[] { new Long(tagId) });
2052
2053 if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
2054 for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2055 for (ModelListener<AssetTag> listener : listeners) {
2056 listener.onAfterRemoveAssociation(tagId,
2057 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2058 assetEntry.getPrimaryKey());
2059 }
2060
2061 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2062 listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
2063 AssetTag.class.getName(), tagId);
2064 }
2065 }
2066 }
2067 }
2068
2069 private SqlUpdate _sqlUpdate;
2070 }
2071
2072 protected class RemoveAssetEntry {
2073 protected RemoveAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
2074 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2075 "DELETE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?",
2076 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2077 _persistenceImpl = persistenceImpl;
2078 }
2079
2080 protected void remove(long tagId, long entryId)
2081 throws SystemException {
2082 if (_persistenceImpl.containsAssetEntry.contains(tagId, entryId)) {
2083 ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
2084 assetEntryPersistence.getListeners();
2085
2086 for (ModelListener<AssetTag> listener : listeners) {
2087 listener.onBeforeRemoveAssociation(tagId,
2088 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2089 entryId);
2090 }
2091
2092 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2093 listener.onBeforeRemoveAssociation(entryId,
2094 AssetTag.class.getName(), tagId);
2095 }
2096
2097 _sqlUpdate.update(new Object[] {
2098 new Long(tagId), new Long(entryId)
2099 });
2100
2101 for (ModelListener<AssetTag> listener : listeners) {
2102 listener.onAfterRemoveAssociation(tagId,
2103 com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2104 entryId);
2105 }
2106
2107 for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2108 listener.onAfterRemoveAssociation(entryId,
2109 AssetTag.class.getName(), tagId);
2110 }
2111 }
2112 }
2113
2114 private SqlUpdate _sqlUpdate;
2115 private AssetTagPersistenceImpl _persistenceImpl;
2116 }
2117
2118 private static final String _SQL_SELECT_ASSETTAG = "SELECT assetTag FROM AssetTag assetTag";
2119 private static final String _SQL_SELECT_ASSETTAG_WHERE = "SELECT assetTag FROM AssetTag assetTag WHERE ";
2120 private static final String _SQL_COUNT_ASSETTAG = "SELECT COUNT(assetTag) FROM AssetTag assetTag";
2121 private static final String _SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(assetTag) FROM AssetTag assetTag WHERE ";
2122 private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetTags ON (AssetEntries_AssetTags.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetTags.tagId = ?)";
2123 private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ?";
2124 private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?";
2125 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetTag.groupId = ?";
2126 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetTag.tagId";
2127 private static final String _FILTER_SQL_SELECT_ASSETTAG_WHERE = "SELECT DISTINCT {assetTag.*} FROM AssetTag assetTag WHERE ";
2128 private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1 =
2129 "SELECT {AssetTag.*} FROM (SELECT DISTINCT assetTag.tagId FROM AssetTag assetTag WHERE ";
2130 private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2 =
2131 ") TEMP_TABLE INNER JOIN AssetTag ON TEMP_TABLE.tagId = AssetTag.tagId";
2132 private static final String _FILTER_SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(DISTINCT assetTag.tagId) AS COUNT_VALUE FROM AssetTag assetTag WHERE ";
2133 private static final String _FILTER_ENTITY_ALIAS = "assetTag";
2134 private static final String _FILTER_ENTITY_TABLE = "AssetTag";
2135 private static final String _ORDER_BY_ENTITY_ALIAS = "assetTag.";
2136 private static final String _ORDER_BY_ENTITY_TABLE = "AssetTag.";
2137 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTag exists with the primary key ";
2138 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTag exists with the key {";
2139 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2140 private static Log _log = LogFactoryUtil.getLog(AssetTagPersistenceImpl.class);
2141 private static AssetTag _nullAssetTag = new AssetTagImpl() {
2142 @Override
2143 public Object clone() {
2144 return this;
2145 }
2146
2147 @Override
2148 public CacheModel<AssetTag> toCacheModel() {
2149 return _nullAssetTagCacheModel;
2150 }
2151 };
2152
2153 private static CacheModel<AssetTag> _nullAssetTagCacheModel = new CacheModel<AssetTag>() {
2154 public AssetTag toEntityModel() {
2155 return _nullAssetTag;
2156 }
2157 };
2158 }