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