1
22
23 package com.liferay.portlet.tags.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.cache.CacheRegistry;
28 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
29 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
30 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
31 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
32 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
33 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
34 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
35 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
36 import com.liferay.portal.kernel.dao.orm.FinderPath;
37 import com.liferay.portal.kernel.dao.orm.Query;
38 import com.liferay.portal.kernel.dao.orm.QueryPos;
39 import com.liferay.portal.kernel.dao.orm.QueryUtil;
40 import com.liferay.portal.kernel.dao.orm.SQLQuery;
41 import com.liferay.portal.kernel.dao.orm.Session;
42 import com.liferay.portal.kernel.dao.orm.Type;
43 import com.liferay.portal.kernel.log.Log;
44 import com.liferay.portal.kernel.log.LogFactoryUtil;
45 import com.liferay.portal.kernel.util.GetterUtil;
46 import com.liferay.portal.kernel.util.OrderByComparator;
47 import com.liferay.portal.kernel.util.SetUtil;
48 import com.liferay.portal.kernel.util.StringPool;
49 import com.liferay.portal.kernel.util.StringUtil;
50 import com.liferay.portal.kernel.util.Validator;
51 import com.liferay.portal.model.ModelListener;
52 import com.liferay.portal.service.persistence.BatchSessionUtil;
53 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
54
55 import com.liferay.portlet.tags.NoSuchEntryException;
56 import com.liferay.portlet.tags.model.TagsEntry;
57 import com.liferay.portlet.tags.model.impl.TagsEntryImpl;
58 import com.liferay.portlet.tags.model.impl.TagsEntryModelImpl;
59
60 import java.sql.Types;
61
62 import java.util.ArrayList;
63 import java.util.Collections;
64 import java.util.List;
65 import java.util.Set;
66
67
80 public class TagsEntryPersistenceImpl extends BasePersistenceImpl
81 implements TagsEntryPersistence {
82 public static final String FINDER_CLASS_NAME_ENTITY = TagsEntryImpl.class.getName();
83 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
84 ".List";
85 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
86 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
87 "fetchByC_N",
88 new String[] { Long.class.getName(), String.class.getName() });
89 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
90 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91 "countByC_N",
92 new String[] { Long.class.getName(), String.class.getName() });
93 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
94 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95 "findAll", new String[0]);
96 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
97 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
98 "countAll", new String[0]);
99
100 public void cacheResult(TagsEntry tagsEntry) {
101 EntityCacheUtil.putResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
102 TagsEntryImpl.class, tagsEntry.getPrimaryKey(), tagsEntry);
103
104 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
105 new Object[] { new Long(tagsEntry.getCompanyId()), tagsEntry.getName() },
106 tagsEntry);
107 }
108
109 public void cacheResult(List<TagsEntry> tagsEntries) {
110 for (TagsEntry tagsEntry : tagsEntries) {
111 if (EntityCacheUtil.getResult(
112 TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
113 TagsEntryImpl.class, tagsEntry.getPrimaryKey(), this) == null) {
114 cacheResult(tagsEntry);
115 }
116 }
117 }
118
119 public void clearCache() {
120 CacheRegistry.clear(TagsEntryImpl.class.getName());
121 EntityCacheUtil.clearCache(TagsEntryImpl.class.getName());
122 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
123 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
124 }
125
126 public TagsEntry create(long entryId) {
127 TagsEntry tagsEntry = new TagsEntryImpl();
128
129 tagsEntry.setNew(true);
130 tagsEntry.setPrimaryKey(entryId);
131
132 return tagsEntry;
133 }
134
135 public TagsEntry remove(long entryId)
136 throws NoSuchEntryException, SystemException {
137 Session session = null;
138
139 try {
140 session = openSession();
141
142 TagsEntry tagsEntry = (TagsEntry)session.get(TagsEntryImpl.class,
143 new Long(entryId));
144
145 if (tagsEntry == null) {
146 if (_log.isWarnEnabled()) {
147 _log.warn("No TagsEntry exists with the primary key " +
148 entryId);
149 }
150
151 throw new NoSuchEntryException(
152 "No TagsEntry exists with the primary key " + entryId);
153 }
154
155 return remove(tagsEntry);
156 }
157 catch (NoSuchEntryException nsee) {
158 throw nsee;
159 }
160 catch (Exception e) {
161 throw processException(e);
162 }
163 finally {
164 closeSession(session);
165 }
166 }
167
168 public TagsEntry remove(TagsEntry tagsEntry) throws SystemException {
169 for (ModelListener<TagsEntry> listener : listeners) {
170 listener.onBeforeRemove(tagsEntry);
171 }
172
173 tagsEntry = removeImpl(tagsEntry);
174
175 for (ModelListener<TagsEntry> listener : listeners) {
176 listener.onAfterRemove(tagsEntry);
177 }
178
179 return tagsEntry;
180 }
181
182 protected TagsEntry removeImpl(TagsEntry tagsEntry)
183 throws SystemException {
184 try {
185 clearTagsAssets.clear(tagsEntry.getPrimaryKey());
186 }
187 catch (Exception e) {
188 throw processException(e);
189 }
190 finally {
191 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
192 }
193
194 Session session = null;
195
196 try {
197 session = openSession();
198
199 if (tagsEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
200 Object staleObject = session.get(TagsEntryImpl.class,
201 tagsEntry.getPrimaryKeyObj());
202
203 if (staleObject != null) {
204 session.evict(staleObject);
205 }
206 }
207
208 session.delete(tagsEntry);
209
210 session.flush();
211 }
212 catch (Exception e) {
213 throw processException(e);
214 }
215 finally {
216 closeSession(session);
217 }
218
219 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
220
221 TagsEntryModelImpl tagsEntryModelImpl = (TagsEntryModelImpl)tagsEntry;
222
223 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
224 new Object[] {
225 new Long(tagsEntryModelImpl.getOriginalCompanyId()),
226
227 tagsEntryModelImpl.getOriginalName()
228 });
229
230 EntityCacheUtil.removeResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
231 TagsEntryImpl.class, tagsEntry.getPrimaryKey());
232
233 return tagsEntry;
234 }
235
236
239 public TagsEntry update(TagsEntry tagsEntry) throws SystemException {
240 if (_log.isWarnEnabled()) {
241 _log.warn(
242 "Using the deprecated update(TagsEntry tagsEntry) method. Use update(TagsEntry tagsEntry, boolean merge) instead.");
243 }
244
245 return update(tagsEntry, false);
246 }
247
248
260 public TagsEntry update(TagsEntry tagsEntry, boolean merge)
261 throws SystemException {
262 boolean isNew = tagsEntry.isNew();
263
264 for (ModelListener<TagsEntry> listener : listeners) {
265 if (isNew) {
266 listener.onBeforeCreate(tagsEntry);
267 }
268 else {
269 listener.onBeforeUpdate(tagsEntry);
270 }
271 }
272
273 tagsEntry = updateImpl(tagsEntry, merge);
274
275 for (ModelListener<TagsEntry> listener : listeners) {
276 if (isNew) {
277 listener.onAfterCreate(tagsEntry);
278 }
279 else {
280 listener.onAfterUpdate(tagsEntry);
281 }
282 }
283
284 return tagsEntry;
285 }
286
287 public TagsEntry updateImpl(
288 com.liferay.portlet.tags.model.TagsEntry tagsEntry, boolean merge)
289 throws SystemException {
290 boolean isNew = tagsEntry.isNew();
291
292 TagsEntryModelImpl tagsEntryModelImpl = (TagsEntryModelImpl)tagsEntry;
293
294 Session session = null;
295
296 try {
297 session = openSession();
298
299 BatchSessionUtil.update(session, tagsEntry, merge);
300
301 tagsEntry.setNew(false);
302 }
303 catch (Exception e) {
304 throw processException(e);
305 }
306 finally {
307 closeSession(session);
308 }
309
310 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
311
312 EntityCacheUtil.putResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
313 TagsEntryImpl.class, tagsEntry.getPrimaryKey(), tagsEntry);
314
315 if (!isNew &&
316 ((tagsEntry.getCompanyId() != tagsEntryModelImpl.getOriginalCompanyId()) ||
317 !Validator.equals(tagsEntry.getName(),
318 tagsEntryModelImpl.getOriginalName()))) {
319 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
320 new Object[] {
321 new Long(tagsEntryModelImpl.getOriginalCompanyId()),
322
323 tagsEntryModelImpl.getOriginalName()
324 });
325 }
326
327 if (isNew ||
328 ((tagsEntry.getCompanyId() != tagsEntryModelImpl.getOriginalCompanyId()) ||
329 !Validator.equals(tagsEntry.getName(),
330 tagsEntryModelImpl.getOriginalName()))) {
331 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
332 new Object[] {
333 new Long(tagsEntry.getCompanyId()),
334
335 tagsEntry.getName()
336 }, tagsEntry);
337 }
338
339 return tagsEntry;
340 }
341
342 public TagsEntry findByPrimaryKey(long entryId)
343 throws NoSuchEntryException, SystemException {
344 TagsEntry tagsEntry = fetchByPrimaryKey(entryId);
345
346 if (tagsEntry == null) {
347 if (_log.isWarnEnabled()) {
348 _log.warn("No TagsEntry exists with the primary key " +
349 entryId);
350 }
351
352 throw new NoSuchEntryException(
353 "No TagsEntry exists with the primary key " + entryId);
354 }
355
356 return tagsEntry;
357 }
358
359 public TagsEntry fetchByPrimaryKey(long entryId) throws SystemException {
360 TagsEntry tagsEntry = (TagsEntry)EntityCacheUtil.getResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
361 TagsEntryImpl.class, entryId, this);
362
363 if (tagsEntry == null) {
364 Session session = null;
365
366 try {
367 session = openSession();
368
369 tagsEntry = (TagsEntry)session.get(TagsEntryImpl.class,
370 new Long(entryId));
371 }
372 catch (Exception e) {
373 throw processException(e);
374 }
375 finally {
376 if (tagsEntry != null) {
377 cacheResult(tagsEntry);
378 }
379
380 closeSession(session);
381 }
382 }
383
384 return tagsEntry;
385 }
386
387 public TagsEntry findByC_N(long companyId, String name)
388 throws NoSuchEntryException, SystemException {
389 TagsEntry tagsEntry = fetchByC_N(companyId, name);
390
391 if (tagsEntry == null) {
392 StringBuilder msg = new StringBuilder();
393
394 msg.append("No TagsEntry exists with the key {");
395
396 msg.append("companyId=" + companyId);
397
398 msg.append(", ");
399 msg.append("name=" + name);
400
401 msg.append(StringPool.CLOSE_CURLY_BRACE);
402
403 if (_log.isWarnEnabled()) {
404 _log.warn(msg.toString());
405 }
406
407 throw new NoSuchEntryException(msg.toString());
408 }
409
410 return tagsEntry;
411 }
412
413 public TagsEntry fetchByC_N(long companyId, String name)
414 throws SystemException {
415 return fetchByC_N(companyId, name, true);
416 }
417
418 public TagsEntry fetchByC_N(long companyId, String name,
419 boolean retrieveFromCache) throws SystemException {
420 Object[] finderArgs = new Object[] { new Long(companyId), name };
421
422 Object result = null;
423
424 if (retrieveFromCache) {
425 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
426 finderArgs, this);
427 }
428
429 if (result == null) {
430 Session session = null;
431
432 try {
433 session = openSession();
434
435 StringBuilder query = new StringBuilder();
436
437 query.append("SELECT tagsEntry FROM TagsEntry tagsEntry WHERE ");
438
439 query.append("tagsEntry.companyId = ?");
440
441 query.append(" AND ");
442
443 if (name == null) {
444 query.append("tagsEntry.name IS NULL");
445 }
446 else {
447 query.append("tagsEntry.name = ?");
448 }
449
450 query.append(" ");
451
452 query.append("ORDER BY ");
453
454 query.append("tagsEntry.name ASC");
455
456 Query q = session.createQuery(query.toString());
457
458 QueryPos qPos = QueryPos.getInstance(q);
459
460 qPos.add(companyId);
461
462 if (name != null) {
463 qPos.add(name);
464 }
465
466 List<TagsEntry> list = q.list();
467
468 result = list;
469
470 TagsEntry tagsEntry = null;
471
472 if (list.isEmpty()) {
473 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
474 finderArgs, list);
475 }
476 else {
477 tagsEntry = list.get(0);
478
479 cacheResult(tagsEntry);
480
481 if ((tagsEntry.getCompanyId() != companyId) ||
482 (tagsEntry.getName() == null) ||
483 !tagsEntry.getName().equals(name)) {
484 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
485 finderArgs, tagsEntry);
486 }
487 }
488
489 return tagsEntry;
490 }
491 catch (Exception e) {
492 throw processException(e);
493 }
494 finally {
495 if (result == null) {
496 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
497 finderArgs, new ArrayList<TagsEntry>());
498 }
499
500 closeSession(session);
501 }
502 }
503 else {
504 if (result instanceof List<?>) {
505 return null;
506 }
507 else {
508 return (TagsEntry)result;
509 }
510 }
511 }
512
513 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
514 throws SystemException {
515 Session session = null;
516
517 try {
518 session = openSession();
519
520 dynamicQuery.compile(session);
521
522 return dynamicQuery.list();
523 }
524 catch (Exception e) {
525 throw processException(e);
526 }
527 finally {
528 closeSession(session);
529 }
530 }
531
532 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
533 int start, int end) throws SystemException {
534 Session session = null;
535
536 try {
537 session = openSession();
538
539 dynamicQuery.setLimit(start, end);
540
541 dynamicQuery.compile(session);
542
543 return dynamicQuery.list();
544 }
545 catch (Exception e) {
546 throw processException(e);
547 }
548 finally {
549 closeSession(session);
550 }
551 }
552
553 public List<TagsEntry> findAll() throws SystemException {
554 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
555 }
556
557 public List<TagsEntry> findAll(int start, int end)
558 throws SystemException {
559 return findAll(start, end, null);
560 }
561
562 public List<TagsEntry> findAll(int start, int end, OrderByComparator obc)
563 throws SystemException {
564 Object[] finderArgs = new Object[] {
565 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
566 };
567
568 List<TagsEntry> list = (List<TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
569 finderArgs, this);
570
571 if (list == null) {
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 StringBuilder query = new StringBuilder();
578
579 query.append("SELECT tagsEntry FROM TagsEntry tagsEntry ");
580
581 if (obc != null) {
582 query.append("ORDER BY ");
583
584 String[] orderByFields = obc.getOrderByFields();
585
586 for (int i = 0; i < orderByFields.length; i++) {
587 query.append("tagsEntry.");
588 query.append(orderByFields[i]);
589
590 if (obc.isAscending()) {
591 query.append(" ASC");
592 }
593 else {
594 query.append(" DESC");
595 }
596
597 if ((i + 1) < orderByFields.length) {
598 query.append(", ");
599 }
600 }
601 }
602
603 else {
604 query.append("ORDER BY ");
605
606 query.append("tagsEntry.name ASC");
607 }
608
609 Query q = session.createQuery(query.toString());
610
611 if (obc == null) {
612 list = (List<TagsEntry>)QueryUtil.list(q, getDialect(),
613 start, end, false);
614
615 Collections.sort(list);
616 }
617 else {
618 list = (List<TagsEntry>)QueryUtil.list(q, getDialect(),
619 start, end);
620 }
621 }
622 catch (Exception e) {
623 throw processException(e);
624 }
625 finally {
626 if (list == null) {
627 list = new ArrayList<TagsEntry>();
628 }
629
630 cacheResult(list);
631
632 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
633
634 closeSession(session);
635 }
636 }
637
638 return list;
639 }
640
641 public void removeByC_N(long companyId, String name)
642 throws NoSuchEntryException, SystemException {
643 TagsEntry tagsEntry = findByC_N(companyId, name);
644
645 remove(tagsEntry);
646 }
647
648 public void removeAll() throws SystemException {
649 for (TagsEntry tagsEntry : findAll()) {
650 remove(tagsEntry);
651 }
652 }
653
654 public int countByC_N(long companyId, String name)
655 throws SystemException {
656 Object[] finderArgs = new Object[] { new Long(companyId), name };
657
658 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
659 finderArgs, this);
660
661 if (count == null) {
662 Session session = null;
663
664 try {
665 session = openSession();
666
667 StringBuilder query = new StringBuilder();
668
669 query.append("SELECT COUNT(tagsEntry) ");
670 query.append("FROM TagsEntry tagsEntry WHERE ");
671
672 query.append("tagsEntry.companyId = ?");
673
674 query.append(" AND ");
675
676 if (name == null) {
677 query.append("tagsEntry.name IS NULL");
678 }
679 else {
680 query.append("tagsEntry.name = ?");
681 }
682
683 query.append(" ");
684
685 Query q = session.createQuery(query.toString());
686
687 QueryPos qPos = QueryPos.getInstance(q);
688
689 qPos.add(companyId);
690
691 if (name != null) {
692 qPos.add(name);
693 }
694
695 count = (Long)q.uniqueResult();
696 }
697 catch (Exception e) {
698 throw processException(e);
699 }
700 finally {
701 if (count == null) {
702 count = Long.valueOf(0);
703 }
704
705 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
706 count);
707
708 closeSession(session);
709 }
710 }
711
712 return count.intValue();
713 }
714
715 public int countAll() throws SystemException {
716 Object[] finderArgs = new Object[0];
717
718 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
719 finderArgs, this);
720
721 if (count == null) {
722 Session session = null;
723
724 try {
725 session = openSession();
726
727 Query q = session.createQuery(
728 "SELECT COUNT(tagsEntry) FROM TagsEntry tagsEntry");
729
730 count = (Long)q.uniqueResult();
731 }
732 catch (Exception e) {
733 throw processException(e);
734 }
735 finally {
736 if (count == null) {
737 count = Long.valueOf(0);
738 }
739
740 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
741 count);
742
743 closeSession(session);
744 }
745 }
746
747 return count.intValue();
748 }
749
750 public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(long pk)
751 throws SystemException {
752 return getTagsAssets(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
753 }
754
755 public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(
756 long pk, int start, int end) throws SystemException {
757 return getTagsAssets(pk, start, end, null);
758 }
759
760 public static final FinderPath FINDER_PATH_GET_TAGSASSETS = new FinderPath(com.liferay.portlet.tags.model.impl.TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
761 TagsEntryModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
762 "TagsAssets_TagsEntries", "getTagsAssets",
763 new String[] {
764 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
765 "com.liferay.portal.kernel.util.OrderByComparator"
766 });
767
768 public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(
769 long pk, int start, int end, OrderByComparator obc)
770 throws SystemException {
771 Object[] finderArgs = new Object[] {
772 new Long(pk), String.valueOf(start), String.valueOf(end),
773 String.valueOf(obc)
774 };
775
776 List<com.liferay.portlet.tags.model.TagsAsset> list = (List<com.liferay.portlet.tags.model.TagsAsset>)FinderCacheUtil.getResult(FINDER_PATH_GET_TAGSASSETS,
777 finderArgs, this);
778
779 if (list == null) {
780 Session session = null;
781
782 try {
783 session = openSession();
784
785 StringBuilder sb = new StringBuilder();
786
787 sb.append(_SQL_GETTAGSASSETS);
788
789 if (obc != null) {
790 sb.append("ORDER BY ");
791 sb.append(obc.getOrderBy());
792 }
793
794 String sql = sb.toString();
795
796 SQLQuery q = session.createSQLQuery(sql);
797
798 q.addEntity("TagsAsset",
799 com.liferay.portlet.tags.model.impl.TagsAssetImpl.class);
800
801 QueryPos qPos = QueryPos.getInstance(q);
802
803 qPos.add(pk);
804
805 list = (List<com.liferay.portlet.tags.model.TagsAsset>)QueryUtil.list(q,
806 getDialect(), start, end);
807 }
808 catch (Exception e) {
809 throw processException(e);
810 }
811 finally {
812 if (list == null) {
813 list = new ArrayList<com.liferay.portlet.tags.model.TagsAsset>();
814 }
815
816 tagsAssetPersistence.cacheResult(list);
817
818 FinderCacheUtil.putResult(FINDER_PATH_GET_TAGSASSETS,
819 finderArgs, list);
820
821 closeSession(session);
822 }
823 }
824
825 return list;
826 }
827
828 public static final FinderPath FINDER_PATH_GET_TAGSASSETS_SIZE = new FinderPath(com.liferay.portlet.tags.model.impl.TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
829 TagsEntryModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
830 "TagsAssets_TagsEntries", "getTagsAssetsSize",
831 new String[] { Long.class.getName() });
832
833 public int getTagsAssetsSize(long pk) throws SystemException {
834 Object[] finderArgs = new Object[] { new Long(pk) };
835
836 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_TAGSASSETS_SIZE,
837 finderArgs, this);
838
839 if (count == null) {
840 Session session = null;
841
842 try {
843 session = openSession();
844
845 SQLQuery q = session.createSQLQuery(_SQL_GETTAGSASSETSSIZE);
846
847 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
848
849 QueryPos qPos = QueryPos.getInstance(q);
850
851 qPos.add(pk);
852
853 count = (Long)q.uniqueResult();
854 }
855 catch (Exception e) {
856 throw processException(e);
857 }
858 finally {
859 if (count == null) {
860 count = Long.valueOf(0);
861 }
862
863 FinderCacheUtil.putResult(FINDER_PATH_GET_TAGSASSETS_SIZE,
864 finderArgs, count);
865
866 closeSession(session);
867 }
868 }
869
870 return count.intValue();
871 }
872
873 public static final FinderPath FINDER_PATH_CONTAINS_TAGSASSET = new FinderPath(com.liferay.portlet.tags.model.impl.TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
874 TagsEntryModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
875 "TagsAssets_TagsEntries", "containsTagsAsset",
876 new String[] { Long.class.getName(), Long.class.getName() });
877
878 public boolean containsTagsAsset(long pk, long tagsAssetPK)
879 throws SystemException {
880 Object[] finderArgs = new Object[] { new Long(pk), new Long(tagsAssetPK) };
881
882 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_TAGSASSET,
883 finderArgs, this);
884
885 if (value == null) {
886 try {
887 value = Boolean.valueOf(containsTagsAsset.contains(pk,
888 tagsAssetPK));
889 }
890 catch (Exception e) {
891 throw processException(e);
892 }
893 finally {
894 if (value == null) {
895 value = Boolean.FALSE;
896 }
897
898 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_TAGSASSET,
899 finderArgs, value);
900 }
901 }
902
903 return value.booleanValue();
904 }
905
906 public boolean containsTagsAssets(long pk) throws SystemException {
907 if (getTagsAssetsSize(pk) > 0) {
908 return true;
909 }
910 else {
911 return false;
912 }
913 }
914
915 public void addTagsAsset(long pk, long tagsAssetPK)
916 throws SystemException {
917 try {
918 addTagsAsset.add(pk, tagsAssetPK);
919 }
920 catch (Exception e) {
921 throw processException(e);
922 }
923 finally {
924 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
925 }
926 }
927
928 public void addTagsAsset(long pk,
929 com.liferay.portlet.tags.model.TagsAsset tagsAsset)
930 throws SystemException {
931 try {
932 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
933 }
934 catch (Exception e) {
935 throw processException(e);
936 }
937 finally {
938 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
939 }
940 }
941
942 public void addTagsAssets(long pk, long[] tagsAssetPKs)
943 throws SystemException {
944 try {
945 for (long tagsAssetPK : tagsAssetPKs) {
946 addTagsAsset.add(pk, tagsAssetPK);
947 }
948 }
949 catch (Exception e) {
950 throw processException(e);
951 }
952 finally {
953 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
954 }
955 }
956
957 public void addTagsAssets(long pk,
958 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
959 throws SystemException {
960 try {
961 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
962 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
963 }
964 }
965 catch (Exception e) {
966 throw processException(e);
967 }
968 finally {
969 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
970 }
971 }
972
973 public void clearTagsAssets(long pk) throws SystemException {
974 try {
975 clearTagsAssets.clear(pk);
976 }
977 catch (Exception e) {
978 throw processException(e);
979 }
980 finally {
981 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
982 }
983 }
984
985 public void removeTagsAsset(long pk, long tagsAssetPK)
986 throws SystemException {
987 try {
988 removeTagsAsset.remove(pk, tagsAssetPK);
989 }
990 catch (Exception e) {
991 throw processException(e);
992 }
993 finally {
994 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
995 }
996 }
997
998 public void removeTagsAsset(long pk,
999 com.liferay.portlet.tags.model.TagsAsset tagsAsset)
1000 throws SystemException {
1001 try {
1002 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
1003 }
1004 catch (Exception e) {
1005 throw processException(e);
1006 }
1007 finally {
1008 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1009 }
1010 }
1011
1012 public void removeTagsAssets(long pk, long[] tagsAssetPKs)
1013 throws SystemException {
1014 try {
1015 for (long tagsAssetPK : tagsAssetPKs) {
1016 removeTagsAsset.remove(pk, tagsAssetPK);
1017 }
1018 }
1019 catch (Exception e) {
1020 throw processException(e);
1021 }
1022 finally {
1023 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1024 }
1025 }
1026
1027 public void removeTagsAssets(long pk,
1028 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
1029 throws SystemException {
1030 try {
1031 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1032 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
1033 }
1034 }
1035 catch (Exception e) {
1036 throw processException(e);
1037 }
1038 finally {
1039 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1040 }
1041 }
1042
1043 public void setTagsAssets(long pk, long[] tagsAssetPKs)
1044 throws SystemException {
1045 try {
1046 Set<Long> tagsAssetPKSet = SetUtil.fromArray(tagsAssetPKs);
1047
1048 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets = getTagsAssets(pk);
1049
1050 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1051 if (!tagsAssetPKSet.contains(tagsAsset.getPrimaryKey())) {
1052 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
1053 }
1054 else {
1055 tagsAssetPKSet.remove(tagsAsset.getPrimaryKey());
1056 }
1057 }
1058
1059 for (Long tagsAssetPK : tagsAssetPKSet) {
1060 addTagsAsset.add(pk, tagsAssetPK);
1061 }
1062 }
1063 catch (Exception e) {
1064 throw processException(e);
1065 }
1066 finally {
1067 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1068 }
1069 }
1070
1071 public void setTagsAssets(long pk,
1072 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
1073 throws SystemException {
1074 try {
1075 long[] tagsAssetPKs = new long[tagsAssets.size()];
1076
1077 for (int i = 0; i < tagsAssets.size(); i++) {
1078 com.liferay.portlet.tags.model.TagsAsset tagsAsset = tagsAssets.get(i);
1079
1080 tagsAssetPKs[i] = tagsAsset.getPrimaryKey();
1081 }
1082
1083 setTagsAssets(pk, tagsAssetPKs);
1084 }
1085 catch (Exception e) {
1086 throw processException(e);
1087 }
1088 finally {
1089 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1090 }
1091 }
1092
1093 public void afterPropertiesSet() {
1094 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1095 com.liferay.portal.util.PropsUtil.get(
1096 "value.object.listener.com.liferay.portlet.tags.model.TagsEntry")));
1097
1098 if (listenerClassNames.length > 0) {
1099 try {
1100 List<ModelListener<TagsEntry>> listenersList = new ArrayList<ModelListener<TagsEntry>>();
1101
1102 for (String listenerClassName : listenerClassNames) {
1103 listenersList.add((ModelListener<TagsEntry>)Class.forName(
1104 listenerClassName).newInstance());
1105 }
1106
1107 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1108 }
1109 catch (Exception e) {
1110 _log.error(e);
1111 }
1112 }
1113
1114 containsTagsAsset = new ContainsTagsAsset(this);
1115
1116 addTagsAsset = new AddTagsAsset(this);
1117 clearTagsAssets = new ClearTagsAssets(this);
1118 removeTagsAsset = new RemoveTagsAsset(this);
1119 }
1120
1121 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1122 protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1123 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1124 protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1125 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1126 protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1127 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1128 protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1129 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1130 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1131 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1132 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1133 protected ContainsTagsAsset containsTagsAsset;
1134 protected AddTagsAsset addTagsAsset;
1135 protected ClearTagsAssets clearTagsAssets;
1136 protected RemoveTagsAsset removeTagsAsset;
1137
1138 protected class ContainsTagsAsset {
1139 protected ContainsTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1140 super();
1141
1142 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1143 _SQL_CONTAINSTAGSASSET,
1144 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1145 }
1146
1147 protected boolean contains(long entryId, long assetId) {
1148 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1149 new Long(entryId), new Long(assetId)
1150 });
1151
1152 if (results.size() > 0) {
1153 Integer count = results.get(0);
1154
1155 if (count.intValue() > 0) {
1156 return true;
1157 }
1158 }
1159
1160 return false;
1161 }
1162
1163 private MappingSqlQuery _mappingSqlQuery;
1164 }
1165
1166 protected class AddTagsAsset {
1167 protected AddTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1168 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1169 "INSERT INTO TagsAssets_TagsEntries (entryId, assetId) VALUES (?, ?)",
1170 new int[] { Types.BIGINT, Types.BIGINT });
1171 _persistenceImpl = persistenceImpl;
1172 }
1173
1174 protected void add(long entryId, long assetId) {
1175 if (!_persistenceImpl.containsTagsAsset.contains(entryId, assetId)) {
1176 _sqlUpdate.update(new Object[] {
1177 new Long(entryId), new Long(assetId)
1178 });
1179 }
1180 }
1181
1182 private SqlUpdate _sqlUpdate;
1183 private TagsEntryPersistenceImpl _persistenceImpl;
1184 }
1185
1186 protected class ClearTagsAssets {
1187 protected ClearTagsAssets(TagsEntryPersistenceImpl persistenceImpl) {
1188 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1189 "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ?",
1190 new int[] { Types.BIGINT });
1191 }
1192
1193 protected void clear(long entryId) {
1194 _sqlUpdate.update(new Object[] { new Long(entryId) });
1195 }
1196
1197 private SqlUpdate _sqlUpdate;
1198 }
1199
1200 protected class RemoveTagsAsset {
1201 protected RemoveTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1202 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1203 "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?",
1204 new int[] { Types.BIGINT, Types.BIGINT });
1205 }
1206
1207 protected void remove(long entryId, long assetId) {
1208 _sqlUpdate.update(new Object[] { new Long(entryId), new Long(
1209 assetId) });
1210 }
1211
1212 private SqlUpdate _sqlUpdate;
1213 }
1214
1215 private static final String _SQL_GETTAGSASSETS = "SELECT {TagsAsset.*} FROM TagsAsset INNER JOIN TagsAssets_TagsEntries ON (TagsAssets_TagsEntries.assetId = TagsAsset.assetId) WHERE (TagsAssets_TagsEntries.entryId = ?)";
1216 private static final String _SQL_GETTAGSASSETSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ?";
1217 private static final String _SQL_CONTAINSTAGSASSET = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?";
1218 private static Log _log = LogFactoryUtil.getLog(TagsEntryPersistenceImpl.class);
1219}