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