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