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.StringPool;
48 import com.liferay.portal.kernel.util.StringUtil;
49 import com.liferay.portal.model.ModelListener;
50 import com.liferay.portal.service.persistence.BatchSessionUtil;
51 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
52
53 import com.liferay.portlet.tags.NoSuchEntryException;
54 import com.liferay.portlet.tags.model.TagsEntry;
55 import com.liferay.portlet.tags.model.impl.TagsEntryImpl;
56 import com.liferay.portlet.tags.model.impl.TagsEntryModelImpl;
57
58 import java.sql.Types;
59
60 import java.util.ArrayList;
61 import java.util.Collections;
62 import java.util.List;
63
64
70 public class TagsEntryPersistenceImpl extends BasePersistenceImpl
71 implements TagsEntryPersistence {
72 public static final String FINDER_CLASS_NAME_ENTITY = TagsEntryImpl.class.getName();
73 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
74 ".List";
75 public static final FinderPath FINDER_PATH_FIND_BY_VOCABULARYID = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
76 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
77 "findByVocabularyId", new String[] { Long.class.getName() });
78 public static final FinderPath FINDER_PATH_FIND_BY_OBC_VOCABULARYID = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
79 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80 "findByVocabularyId",
81 new String[] {
82 Long.class.getName(),
83
84 "java.lang.Integer", "java.lang.Integer",
85 "com.liferay.portal.kernel.util.OrderByComparator"
86 });
87 public static final FinderPath FINDER_PATH_COUNT_BY_VOCABULARYID = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
88 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89 "countByVocabularyId", new String[] { Long.class.getName() });
90 public static final FinderPath FINDER_PATH_FIND_BY_P_V = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
91 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92 "findByP_V",
93 new String[] { Long.class.getName(), Long.class.getName() });
94 public static final FinderPath FINDER_PATH_FIND_BY_OBC_P_V = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
95 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96 "findByP_V",
97 new String[] {
98 Long.class.getName(), Long.class.getName(),
99
100 "java.lang.Integer", "java.lang.Integer",
101 "com.liferay.portal.kernel.util.OrderByComparator"
102 });
103 public static final FinderPath FINDER_PATH_COUNT_BY_P_V = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
104 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105 "countByP_V",
106 new String[] { Long.class.getName(), Long.class.getName() });
107 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
108 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109 "findAll", new String[0]);
110 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
111 TagsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112 "countAll", new String[0]);
113
114 public void cacheResult(TagsEntry tagsEntry) {
115 EntityCacheUtil.putResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
116 TagsEntryImpl.class, tagsEntry.getPrimaryKey(), tagsEntry);
117 }
118
119 public void cacheResult(List<TagsEntry> tagsEntries) {
120 for (TagsEntry tagsEntry : tagsEntries) {
121 if (EntityCacheUtil.getResult(
122 TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
123 TagsEntryImpl.class, tagsEntry.getPrimaryKey(), this) == null) {
124 cacheResult(tagsEntry);
125 }
126 }
127 }
128
129 public void clearCache() {
130 CacheRegistry.clear(TagsEntryImpl.class.getName());
131 EntityCacheUtil.clearCache(TagsEntryImpl.class.getName());
132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
133 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
134 }
135
136 public TagsEntry create(long entryId) {
137 TagsEntry tagsEntry = new TagsEntryImpl();
138
139 tagsEntry.setNew(true);
140 tagsEntry.setPrimaryKey(entryId);
141
142 return tagsEntry;
143 }
144
145 public TagsEntry remove(long entryId)
146 throws NoSuchEntryException, SystemException {
147 Session session = null;
148
149 try {
150 session = openSession();
151
152 TagsEntry tagsEntry = (TagsEntry)session.get(TagsEntryImpl.class,
153 new Long(entryId));
154
155 if (tagsEntry == null) {
156 if (_log.isWarnEnabled()) {
157 _log.warn("No TagsEntry exists with the primary key " +
158 entryId);
159 }
160
161 throw new NoSuchEntryException(
162 "No TagsEntry exists with the primary key " + entryId);
163 }
164
165 return remove(tagsEntry);
166 }
167 catch (NoSuchEntryException nsee) {
168 throw nsee;
169 }
170 catch (Exception e) {
171 throw processException(e);
172 }
173 finally {
174 closeSession(session);
175 }
176 }
177
178 public TagsEntry remove(TagsEntry tagsEntry) throws SystemException {
179 for (ModelListener<TagsEntry> listener : listeners) {
180 listener.onBeforeRemove(tagsEntry);
181 }
182
183 tagsEntry = removeImpl(tagsEntry);
184
185 for (ModelListener<TagsEntry> listener : listeners) {
186 listener.onAfterRemove(tagsEntry);
187 }
188
189 return tagsEntry;
190 }
191
192 protected TagsEntry removeImpl(TagsEntry tagsEntry)
193 throws SystemException {
194 try {
195 clearTagsAssets.clear(tagsEntry.getPrimaryKey());
196 }
197 catch (Exception e) {
198 throw processException(e);
199 }
200 finally {
201 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
202 }
203
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 if (tagsEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
210 Object staleObject = session.get(TagsEntryImpl.class,
211 tagsEntry.getPrimaryKeyObj());
212
213 if (staleObject != null) {
214 session.evict(staleObject);
215 }
216 }
217
218 session.delete(tagsEntry);
219
220 session.flush();
221 }
222 catch (Exception e) {
223 throw processException(e);
224 }
225 finally {
226 closeSession(session);
227 }
228
229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
230
231 EntityCacheUtil.removeResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
232 TagsEntryImpl.class, tagsEntry.getPrimaryKey());
233
234 return tagsEntry;
235 }
236
237
240 public TagsEntry update(TagsEntry tagsEntry) throws SystemException {
241 if (_log.isWarnEnabled()) {
242 _log.warn(
243 "Using the deprecated update(TagsEntry tagsEntry) method. Use update(TagsEntry tagsEntry, boolean merge) instead.");
244 }
245
246 return update(tagsEntry, false);
247 }
248
249
262 public TagsEntry update(TagsEntry tagsEntry, boolean merge)
263 throws SystemException {
264 boolean isNew = tagsEntry.isNew();
265
266 for (ModelListener<TagsEntry> listener : listeners) {
267 if (isNew) {
268 listener.onBeforeCreate(tagsEntry);
269 }
270 else {
271 listener.onBeforeUpdate(tagsEntry);
272 }
273 }
274
275 tagsEntry = updateImpl(tagsEntry, merge);
276
277 for (ModelListener<TagsEntry> listener : listeners) {
278 if (isNew) {
279 listener.onAfterCreate(tagsEntry);
280 }
281 else {
282 listener.onAfterUpdate(tagsEntry);
283 }
284 }
285
286 return tagsEntry;
287 }
288
289 public TagsEntry updateImpl(
290 com.liferay.portlet.tags.model.TagsEntry tagsEntry, boolean merge)
291 throws SystemException {
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 BatchSessionUtil.update(session, tagsEntry, merge);
298
299 tagsEntry.setNew(false);
300 }
301 catch (Exception e) {
302 throw processException(e);
303 }
304 finally {
305 closeSession(session);
306 }
307
308 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
309
310 EntityCacheUtil.putResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
311 TagsEntryImpl.class, tagsEntry.getPrimaryKey(), tagsEntry);
312
313 return tagsEntry;
314 }
315
316 public TagsEntry findByPrimaryKey(long entryId)
317 throws NoSuchEntryException, SystemException {
318 TagsEntry tagsEntry = fetchByPrimaryKey(entryId);
319
320 if (tagsEntry == null) {
321 if (_log.isWarnEnabled()) {
322 _log.warn("No TagsEntry exists with the primary key " +
323 entryId);
324 }
325
326 throw new NoSuchEntryException(
327 "No TagsEntry exists with the primary key " + entryId);
328 }
329
330 return tagsEntry;
331 }
332
333 public TagsEntry fetchByPrimaryKey(long entryId) throws SystemException {
334 TagsEntry tagsEntry = (TagsEntry)EntityCacheUtil.getResult(TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
335 TagsEntryImpl.class, entryId, this);
336
337 if (tagsEntry == null) {
338 Session session = null;
339
340 try {
341 session = openSession();
342
343 tagsEntry = (TagsEntry)session.get(TagsEntryImpl.class,
344 new Long(entryId));
345 }
346 catch (Exception e) {
347 throw processException(e);
348 }
349 finally {
350 if (tagsEntry != null) {
351 cacheResult(tagsEntry);
352 }
353
354 closeSession(session);
355 }
356 }
357
358 return tagsEntry;
359 }
360
361 public List<TagsEntry> findByVocabularyId(long vocabularyId)
362 throws SystemException {
363 Object[] finderArgs = new Object[] { new Long(vocabularyId) };
364
365 List<TagsEntry> list = (List<TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_VOCABULARYID,
366 finderArgs, this);
367
368 if (list == null) {
369 Session session = null;
370
371 try {
372 session = openSession();
373
374 StringBuilder query = new StringBuilder();
375
376 query.append(
377 "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
378
379 query.append("vocabularyId = ?");
380
381 query.append(" ");
382
383 query.append("ORDER BY ");
384
385 query.append("name ASC");
386
387 Query q = session.createQuery(query.toString());
388
389 QueryPos qPos = QueryPos.getInstance(q);
390
391 qPos.add(vocabularyId);
392
393 list = q.list();
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 if (list == null) {
400 list = new ArrayList<TagsEntry>();
401 }
402
403 cacheResult(list);
404
405 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_VOCABULARYID,
406 finderArgs, list);
407
408 closeSession(session);
409 }
410 }
411
412 return list;
413 }
414
415 public List<TagsEntry> findByVocabularyId(long vocabularyId, int start,
416 int end) throws SystemException {
417 return findByVocabularyId(vocabularyId, start, end, null);
418 }
419
420 public List<TagsEntry> findByVocabularyId(long vocabularyId, int start,
421 int end, OrderByComparator obc) throws SystemException {
422 Object[] finderArgs = new Object[] {
423 new Long(vocabularyId),
424
425 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
426 };
427
428 List<TagsEntry> list = (List<TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_VOCABULARYID,
429 finderArgs, this);
430
431 if (list == null) {
432 Session session = null;
433
434 try {
435 session = openSession();
436
437 StringBuilder query = new StringBuilder();
438
439 query.append(
440 "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
441
442 query.append("vocabularyId = ?");
443
444 query.append(" ");
445
446 if (obc != null) {
447 query.append("ORDER BY ");
448 query.append(obc.getOrderBy());
449 }
450
451 else {
452 query.append("ORDER BY ");
453
454 query.append("name ASC");
455 }
456
457 Query q = session.createQuery(query.toString());
458
459 QueryPos qPos = QueryPos.getInstance(q);
460
461 qPos.add(vocabularyId);
462
463 list = (List<TagsEntry>)QueryUtil.list(q, getDialect(), start,
464 end);
465 }
466 catch (Exception e) {
467 throw processException(e);
468 }
469 finally {
470 if (list == null) {
471 list = new ArrayList<TagsEntry>();
472 }
473
474 cacheResult(list);
475
476 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_VOCABULARYID,
477 finderArgs, list);
478
479 closeSession(session);
480 }
481 }
482
483 return list;
484 }
485
486 public TagsEntry findByVocabularyId_First(long vocabularyId,
487 OrderByComparator obc) throws NoSuchEntryException, SystemException {
488 List<TagsEntry> list = findByVocabularyId(vocabularyId, 0, 1, obc);
489
490 if (list.isEmpty()) {
491 StringBuilder msg = new StringBuilder();
492
493 msg.append("No TagsEntry exists with the key {");
494
495 msg.append("vocabularyId=" + vocabularyId);
496
497 msg.append(StringPool.CLOSE_CURLY_BRACE);
498
499 throw new NoSuchEntryException(msg.toString());
500 }
501 else {
502 return list.get(0);
503 }
504 }
505
506 public TagsEntry findByVocabularyId_Last(long vocabularyId,
507 OrderByComparator obc) throws NoSuchEntryException, SystemException {
508 int count = countByVocabularyId(vocabularyId);
509
510 List<TagsEntry> list = findByVocabularyId(vocabularyId, count - 1,
511 count, obc);
512
513 if (list.isEmpty()) {
514 StringBuilder msg = new StringBuilder();
515
516 msg.append("No TagsEntry exists with the key {");
517
518 msg.append("vocabularyId=" + vocabularyId);
519
520 msg.append(StringPool.CLOSE_CURLY_BRACE);
521
522 throw new NoSuchEntryException(msg.toString());
523 }
524 else {
525 return list.get(0);
526 }
527 }
528
529 public TagsEntry[] findByVocabularyId_PrevAndNext(long entryId,
530 long vocabularyId, OrderByComparator obc)
531 throws NoSuchEntryException, SystemException {
532 TagsEntry tagsEntry = findByPrimaryKey(entryId);
533
534 int count = countByVocabularyId(vocabularyId);
535
536 Session session = null;
537
538 try {
539 session = openSession();
540
541 StringBuilder query = new StringBuilder();
542
543 query.append("FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
544
545 query.append("vocabularyId = ?");
546
547 query.append(" ");
548
549 if (obc != null) {
550 query.append("ORDER BY ");
551 query.append(obc.getOrderBy());
552 }
553
554 else {
555 query.append("ORDER BY ");
556
557 query.append("name ASC");
558 }
559
560 Query q = session.createQuery(query.toString());
561
562 QueryPos qPos = QueryPos.getInstance(q);
563
564 qPos.add(vocabularyId);
565
566 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
567 tagsEntry);
568
569 TagsEntry[] array = new TagsEntryImpl[3];
570
571 array[0] = (TagsEntry)objArray[0];
572 array[1] = (TagsEntry)objArray[1];
573 array[2] = (TagsEntry)objArray[2];
574
575 return array;
576 }
577 catch (Exception e) {
578 throw processException(e);
579 }
580 finally {
581 closeSession(session);
582 }
583 }
584
585 public List<TagsEntry> findByP_V(long parentEntryId, long vocabularyId)
586 throws SystemException {
587 Object[] finderArgs = new Object[] {
588 new Long(parentEntryId), new Long(vocabularyId)
589 };
590
591 List<TagsEntry> list = (List<TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_P_V,
592 finderArgs, this);
593
594 if (list == null) {
595 Session session = null;
596
597 try {
598 session = openSession();
599
600 StringBuilder query = new StringBuilder();
601
602 query.append(
603 "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
604
605 query.append("parentEntryId = ?");
606
607 query.append(" AND ");
608
609 query.append("vocabularyId = ?");
610
611 query.append(" ");
612
613 query.append("ORDER BY ");
614
615 query.append("name ASC");
616
617 Query q = session.createQuery(query.toString());
618
619 QueryPos qPos = QueryPos.getInstance(q);
620
621 qPos.add(parentEntryId);
622
623 qPos.add(vocabularyId);
624
625 list = q.list();
626 }
627 catch (Exception e) {
628 throw processException(e);
629 }
630 finally {
631 if (list == null) {
632 list = new ArrayList<TagsEntry>();
633 }
634
635 cacheResult(list);
636
637 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_P_V, finderArgs,
638 list);
639
640 closeSession(session);
641 }
642 }
643
644 return list;
645 }
646
647 public List<TagsEntry> findByP_V(long parentEntryId, long vocabularyId,
648 int start, int end) throws SystemException {
649 return findByP_V(parentEntryId, vocabularyId, start, end, null);
650 }
651
652 public List<TagsEntry> findByP_V(long parentEntryId, long vocabularyId,
653 int start, int end, OrderByComparator obc) throws SystemException {
654 Object[] finderArgs = new Object[] {
655 new Long(parentEntryId), new Long(vocabularyId),
656
657 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
658 };
659
660 List<TagsEntry> list = (List<TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_P_V,
661 finderArgs, this);
662
663 if (list == null) {
664 Session session = null;
665
666 try {
667 session = openSession();
668
669 StringBuilder query = new StringBuilder();
670
671 query.append(
672 "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
673
674 query.append("parentEntryId = ?");
675
676 query.append(" AND ");
677
678 query.append("vocabularyId = ?");
679
680 query.append(" ");
681
682 if (obc != null) {
683 query.append("ORDER BY ");
684 query.append(obc.getOrderBy());
685 }
686
687 else {
688 query.append("ORDER BY ");
689
690 query.append("name ASC");
691 }
692
693 Query q = session.createQuery(query.toString());
694
695 QueryPos qPos = QueryPos.getInstance(q);
696
697 qPos.add(parentEntryId);
698
699 qPos.add(vocabularyId);
700
701 list = (List<TagsEntry>)QueryUtil.list(q, getDialect(), start,
702 end);
703 }
704 catch (Exception e) {
705 throw processException(e);
706 }
707 finally {
708 if (list == null) {
709 list = new ArrayList<TagsEntry>();
710 }
711
712 cacheResult(list);
713
714 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_P_V,
715 finderArgs, list);
716
717 closeSession(session);
718 }
719 }
720
721 return list;
722 }
723
724 public TagsEntry findByP_V_First(long parentEntryId, long vocabularyId,
725 OrderByComparator obc) throws NoSuchEntryException, SystemException {
726 List<TagsEntry> list = findByP_V(parentEntryId, vocabularyId, 0, 1, obc);
727
728 if (list.isEmpty()) {
729 StringBuilder msg = new StringBuilder();
730
731 msg.append("No TagsEntry exists with the key {");
732
733 msg.append("parentEntryId=" + parentEntryId);
734
735 msg.append(", ");
736 msg.append("vocabularyId=" + vocabularyId);
737
738 msg.append(StringPool.CLOSE_CURLY_BRACE);
739
740 throw new NoSuchEntryException(msg.toString());
741 }
742 else {
743 return list.get(0);
744 }
745 }
746
747 public TagsEntry findByP_V_Last(long parentEntryId, long vocabularyId,
748 OrderByComparator obc) throws NoSuchEntryException, SystemException {
749 int count = countByP_V(parentEntryId, vocabularyId);
750
751 List<TagsEntry> list = findByP_V(parentEntryId, vocabularyId,
752 count - 1, count, obc);
753
754 if (list.isEmpty()) {
755 StringBuilder msg = new StringBuilder();
756
757 msg.append("No TagsEntry exists with the key {");
758
759 msg.append("parentEntryId=" + parentEntryId);
760
761 msg.append(", ");
762 msg.append("vocabularyId=" + vocabularyId);
763
764 msg.append(StringPool.CLOSE_CURLY_BRACE);
765
766 throw new NoSuchEntryException(msg.toString());
767 }
768 else {
769 return list.get(0);
770 }
771 }
772
773 public TagsEntry[] findByP_V_PrevAndNext(long entryId, long parentEntryId,
774 long vocabularyId, OrderByComparator obc)
775 throws NoSuchEntryException, SystemException {
776 TagsEntry tagsEntry = findByPrimaryKey(entryId);
777
778 int count = countByP_V(parentEntryId, vocabularyId);
779
780 Session session = null;
781
782 try {
783 session = openSession();
784
785 StringBuilder query = new StringBuilder();
786
787 query.append("FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
788
789 query.append("parentEntryId = ?");
790
791 query.append(" AND ");
792
793 query.append("vocabularyId = ?");
794
795 query.append(" ");
796
797 if (obc != null) {
798 query.append("ORDER BY ");
799 query.append(obc.getOrderBy());
800 }
801
802 else {
803 query.append("ORDER BY ");
804
805 query.append("name ASC");
806 }
807
808 Query q = session.createQuery(query.toString());
809
810 QueryPos qPos = QueryPos.getInstance(q);
811
812 qPos.add(parentEntryId);
813
814 qPos.add(vocabularyId);
815
816 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
817 tagsEntry);
818
819 TagsEntry[] array = new TagsEntryImpl[3];
820
821 array[0] = (TagsEntry)objArray[0];
822 array[1] = (TagsEntry)objArray[1];
823 array[2] = (TagsEntry)objArray[2];
824
825 return array;
826 }
827 catch (Exception e) {
828 throw processException(e);
829 }
830 finally {
831 closeSession(session);
832 }
833 }
834
835 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
836 throws SystemException {
837 Session session = null;
838
839 try {
840 session = openSession();
841
842 dynamicQuery.compile(session);
843
844 return dynamicQuery.list();
845 }
846 catch (Exception e) {
847 throw processException(e);
848 }
849 finally {
850 closeSession(session);
851 }
852 }
853
854 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
855 int start, int end) throws SystemException {
856 Session session = null;
857
858 try {
859 session = openSession();
860
861 dynamicQuery.setLimit(start, end);
862
863 dynamicQuery.compile(session);
864
865 return dynamicQuery.list();
866 }
867 catch (Exception e) {
868 throw processException(e);
869 }
870 finally {
871 closeSession(session);
872 }
873 }
874
875 public List<TagsEntry> findAll() throws SystemException {
876 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
877 }
878
879 public List<TagsEntry> findAll(int start, int end)
880 throws SystemException {
881 return findAll(start, end, null);
882 }
883
884 public List<TagsEntry> findAll(int start, int end, OrderByComparator obc)
885 throws SystemException {
886 Object[] finderArgs = new Object[] {
887 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
888 };
889
890 List<TagsEntry> list = (List<TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
891 finderArgs, this);
892
893 if (list == null) {
894 Session session = null;
895
896 try {
897 session = openSession();
898
899 StringBuilder query = new StringBuilder();
900
901 query.append("FROM com.liferay.portlet.tags.model.TagsEntry ");
902
903 if (obc != null) {
904 query.append("ORDER BY ");
905 query.append(obc.getOrderBy());
906 }
907
908 else {
909 query.append("ORDER BY ");
910
911 query.append("name ASC");
912 }
913
914 Query q = session.createQuery(query.toString());
915
916 if (obc == null) {
917 list = (List<TagsEntry>)QueryUtil.list(q, getDialect(),
918 start, end, false);
919
920 Collections.sort(list);
921 }
922 else {
923 list = (List<TagsEntry>)QueryUtil.list(q, getDialect(),
924 start, end);
925 }
926 }
927 catch (Exception e) {
928 throw processException(e);
929 }
930 finally {
931 if (list == null) {
932 list = new ArrayList<TagsEntry>();
933 }
934
935 cacheResult(list);
936
937 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
938
939 closeSession(session);
940 }
941 }
942
943 return list;
944 }
945
946 public void removeByVocabularyId(long vocabularyId)
947 throws SystemException {
948 for (TagsEntry tagsEntry : findByVocabularyId(vocabularyId)) {
949 remove(tagsEntry);
950 }
951 }
952
953 public void removeByP_V(long parentEntryId, long vocabularyId)
954 throws SystemException {
955 for (TagsEntry tagsEntry : findByP_V(parentEntryId, vocabularyId)) {
956 remove(tagsEntry);
957 }
958 }
959
960 public void removeAll() throws SystemException {
961 for (TagsEntry tagsEntry : findAll()) {
962 remove(tagsEntry);
963 }
964 }
965
966 public int countByVocabularyId(long vocabularyId) throws SystemException {
967 Object[] finderArgs = new Object[] { new Long(vocabularyId) };
968
969 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
970 finderArgs, this);
971
972 if (count == null) {
973 Session session = null;
974
975 try {
976 session = openSession();
977
978 StringBuilder query = new StringBuilder();
979
980 query.append("SELECT COUNT(*) ");
981 query.append(
982 "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
983
984 query.append("vocabularyId = ?");
985
986 query.append(" ");
987
988 Query q = session.createQuery(query.toString());
989
990 QueryPos qPos = QueryPos.getInstance(q);
991
992 qPos.add(vocabularyId);
993
994 count = (Long)q.uniqueResult();
995 }
996 catch (Exception e) {
997 throw processException(e);
998 }
999 finally {
1000 if (count == null) {
1001 count = Long.valueOf(0);
1002 }
1003
1004 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
1005 finderArgs, count);
1006
1007 closeSession(session);
1008 }
1009 }
1010
1011 return count.intValue();
1012 }
1013
1014 public int countByP_V(long parentEntryId, long vocabularyId)
1015 throws SystemException {
1016 Object[] finderArgs = new Object[] {
1017 new Long(parentEntryId), new Long(vocabularyId)
1018 };
1019
1020 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_V,
1021 finderArgs, this);
1022
1023 if (count == null) {
1024 Session session = null;
1025
1026 try {
1027 session = openSession();
1028
1029 StringBuilder query = new StringBuilder();
1030
1031 query.append("SELECT COUNT(*) ");
1032 query.append(
1033 "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
1034
1035 query.append("parentEntryId = ?");
1036
1037 query.append(" AND ");
1038
1039 query.append("vocabularyId = ?");
1040
1041 query.append(" ");
1042
1043 Query q = session.createQuery(query.toString());
1044
1045 QueryPos qPos = QueryPos.getInstance(q);
1046
1047 qPos.add(parentEntryId);
1048
1049 qPos.add(vocabularyId);
1050
1051 count = (Long)q.uniqueResult();
1052 }
1053 catch (Exception e) {
1054 throw processException(e);
1055 }
1056 finally {
1057 if (count == null) {
1058 count = Long.valueOf(0);
1059 }
1060
1061 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_V, finderArgs,
1062 count);
1063
1064 closeSession(session);
1065 }
1066 }
1067
1068 return count.intValue();
1069 }
1070
1071 public int countAll() throws SystemException {
1072 Object[] finderArgs = new Object[0];
1073
1074 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1075 finderArgs, this);
1076
1077 if (count == null) {
1078 Session session = null;
1079
1080 try {
1081 session = openSession();
1082
1083 Query q = session.createQuery(
1084 "SELECT COUNT(*) FROM com.liferay.portlet.tags.model.TagsEntry");
1085
1086 count = (Long)q.uniqueResult();
1087 }
1088 catch (Exception e) {
1089 throw processException(e);
1090 }
1091 finally {
1092 if (count == null) {
1093 count = Long.valueOf(0);
1094 }
1095
1096 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1097 count);
1098
1099 closeSession(session);
1100 }
1101 }
1102
1103 return count.intValue();
1104 }
1105
1106 public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(long pk)
1107 throws SystemException {
1108 return getTagsAssets(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1109 }
1110
1111 public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(
1112 long pk, int start, int end) throws SystemException {
1113 return getTagsAssets(pk, start, end, null);
1114 }
1115
1116 public static final FinderPath FINDER_PATH_GET_TAGSASSETS = new FinderPath(com.liferay.portlet.tags.model.impl.TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
1117 TagsEntryModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
1118 "TagsAssets_TagsEntries", "getTagsAssets",
1119 new String[] {
1120 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1121 "com.liferay.portal.kernel.util.OrderByComparator"
1122 });
1123
1124 public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(
1125 long pk, int start, int end, OrderByComparator obc)
1126 throws SystemException {
1127 Object[] finderArgs = new Object[] {
1128 new Long(pk), String.valueOf(start), String.valueOf(end),
1129 String.valueOf(obc)
1130 };
1131
1132 List<com.liferay.portlet.tags.model.TagsAsset> list = (List<com.liferay.portlet.tags.model.TagsAsset>)FinderCacheUtil.getResult(FINDER_PATH_GET_TAGSASSETS,
1133 finderArgs, this);
1134
1135 if (list == null) {
1136 Session session = null;
1137
1138 try {
1139 session = openSession();
1140
1141 StringBuilder sb = new StringBuilder();
1142
1143 sb.append(_SQL_GETTAGSASSETS);
1144
1145 if (obc != null) {
1146 sb.append("ORDER BY ");
1147 sb.append(obc.getOrderBy());
1148 }
1149
1150 String sql = sb.toString();
1151
1152 SQLQuery q = session.createSQLQuery(sql);
1153
1154 q.addEntity("TagsAsset",
1155 com.liferay.portlet.tags.model.impl.TagsAssetImpl.class);
1156
1157 QueryPos qPos = QueryPos.getInstance(q);
1158
1159 qPos.add(pk);
1160
1161 list = (List<com.liferay.portlet.tags.model.TagsAsset>)QueryUtil.list(q,
1162 getDialect(), start, end);
1163 }
1164 catch (Exception e) {
1165 throw processException(e);
1166 }
1167 finally {
1168 if (list == null) {
1169 list = new ArrayList<com.liferay.portlet.tags.model.TagsAsset>();
1170 }
1171
1172 tagsAssetPersistence.cacheResult(list);
1173
1174 FinderCacheUtil.putResult(FINDER_PATH_GET_TAGSASSETS,
1175 finderArgs, list);
1176
1177 closeSession(session);
1178 }
1179 }
1180
1181 return list;
1182 }
1183
1184 public static final FinderPath FINDER_PATH_GET_TAGSASSETS_SIZE = new FinderPath(com.liferay.portlet.tags.model.impl.TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
1185 TagsEntryModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
1186 "TagsAssets_TagsEntries", "getTagsAssetsSize",
1187 new String[] { Long.class.getName() });
1188
1189 public int getTagsAssetsSize(long pk) throws SystemException {
1190 Object[] finderArgs = new Object[] { new Long(pk) };
1191
1192 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_TAGSASSETS_SIZE,
1193 finderArgs, this);
1194
1195 if (count == null) {
1196 Session session = null;
1197
1198 try {
1199 session = openSession();
1200
1201 SQLQuery q = session.createSQLQuery(_SQL_GETTAGSASSETSSIZE);
1202
1203 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1204
1205 QueryPos qPos = QueryPos.getInstance(q);
1206
1207 qPos.add(pk);
1208
1209 count = (Long)q.uniqueResult();
1210 }
1211 catch (Exception e) {
1212 throw processException(e);
1213 }
1214 finally {
1215 if (count == null) {
1216 count = Long.valueOf(0);
1217 }
1218
1219 FinderCacheUtil.putResult(FINDER_PATH_GET_TAGSASSETS_SIZE,
1220 finderArgs, count);
1221
1222 closeSession(session);
1223 }
1224 }
1225
1226 return count.intValue();
1227 }
1228
1229 public static final FinderPath FINDER_PATH_CONTAINS_TAGSASSET = new FinderPath(com.liferay.portlet.tags.model.impl.TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
1230 TagsEntryModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
1231 "TagsAssets_TagsEntries", "containsTagsAsset",
1232 new String[] { Long.class.getName(), Long.class.getName() });
1233
1234 public boolean containsTagsAsset(long pk, long tagsAssetPK)
1235 throws SystemException {
1236 Object[] finderArgs = new Object[] { new Long(pk), new Long(tagsAssetPK) };
1237
1238 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_TAGSASSET,
1239 finderArgs, this);
1240
1241 if (value == null) {
1242 try {
1243 value = Boolean.valueOf(containsTagsAsset.contains(pk,
1244 tagsAssetPK));
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 if (value == null) {
1251 value = Boolean.FALSE;
1252 }
1253
1254 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_TAGSASSET,
1255 finderArgs, value);
1256 }
1257 }
1258
1259 return value.booleanValue();
1260 }
1261
1262 public boolean containsTagsAssets(long pk) throws SystemException {
1263 if (getTagsAssetsSize(pk) > 0) {
1264 return true;
1265 }
1266 else {
1267 return false;
1268 }
1269 }
1270
1271 public void addTagsAsset(long pk, long tagsAssetPK)
1272 throws SystemException {
1273 try {
1274 addTagsAsset.add(pk, tagsAssetPK);
1275 }
1276 catch (Exception e) {
1277 throw processException(e);
1278 }
1279 finally {
1280 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1281 }
1282 }
1283
1284 public void addTagsAsset(long pk,
1285 com.liferay.portlet.tags.model.TagsAsset tagsAsset)
1286 throws SystemException {
1287 try {
1288 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
1289 }
1290 catch (Exception e) {
1291 throw processException(e);
1292 }
1293 finally {
1294 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1295 }
1296 }
1297
1298 public void addTagsAssets(long pk, long[] tagsAssetPKs)
1299 throws SystemException {
1300 try {
1301 for (long tagsAssetPK : tagsAssetPKs) {
1302 addTagsAsset.add(pk, tagsAssetPK);
1303 }
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1310 }
1311 }
1312
1313 public void addTagsAssets(long pk,
1314 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
1315 throws SystemException {
1316 try {
1317 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1318 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
1319 }
1320 }
1321 catch (Exception e) {
1322 throw processException(e);
1323 }
1324 finally {
1325 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1326 }
1327 }
1328
1329 public void clearTagsAssets(long pk) throws SystemException {
1330 try {
1331 clearTagsAssets.clear(pk);
1332 }
1333 catch (Exception e) {
1334 throw processException(e);
1335 }
1336 finally {
1337 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1338 }
1339 }
1340
1341 public void removeTagsAsset(long pk, long tagsAssetPK)
1342 throws SystemException {
1343 try {
1344 removeTagsAsset.remove(pk, tagsAssetPK);
1345 }
1346 catch (Exception e) {
1347 throw processException(e);
1348 }
1349 finally {
1350 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1351 }
1352 }
1353
1354 public void removeTagsAsset(long pk,
1355 com.liferay.portlet.tags.model.TagsAsset tagsAsset)
1356 throws SystemException {
1357 try {
1358 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
1359 }
1360 catch (Exception e) {
1361 throw processException(e);
1362 }
1363 finally {
1364 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1365 }
1366 }
1367
1368 public void removeTagsAssets(long pk, long[] tagsAssetPKs)
1369 throws SystemException {
1370 try {
1371 for (long tagsAssetPK : tagsAssetPKs) {
1372 removeTagsAsset.remove(pk, tagsAssetPK);
1373 }
1374 }
1375 catch (Exception e) {
1376 throw processException(e);
1377 }
1378 finally {
1379 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1380 }
1381 }
1382
1383 public void removeTagsAssets(long pk,
1384 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
1385 throws SystemException {
1386 try {
1387 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1388 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
1389 }
1390 }
1391 catch (Exception e) {
1392 throw processException(e);
1393 }
1394 finally {
1395 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1396 }
1397 }
1398
1399 public void setTagsAssets(long pk, long[] tagsAssetPKs)
1400 throws SystemException {
1401 try {
1402 clearTagsAssets.clear(pk);
1403
1404 for (long tagsAssetPK : tagsAssetPKs) {
1405 addTagsAsset.add(pk, tagsAssetPK);
1406 }
1407 }
1408 catch (Exception e) {
1409 throw processException(e);
1410 }
1411 finally {
1412 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1413 }
1414 }
1415
1416 public void setTagsAssets(long pk,
1417 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
1418 throws SystemException {
1419 try {
1420 clearTagsAssets.clear(pk);
1421
1422 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1423 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
1424 }
1425 }
1426 catch (Exception e) {
1427 throw processException(e);
1428 }
1429 finally {
1430 FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1431 }
1432 }
1433
1434 public void afterPropertiesSet() {
1435 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1436 com.liferay.portal.util.PropsUtil.get(
1437 "value.object.listener.com.liferay.portlet.tags.model.TagsEntry")));
1438
1439 if (listenerClassNames.length > 0) {
1440 try {
1441 List<ModelListener<TagsEntry>> listenersList = new ArrayList<ModelListener<TagsEntry>>();
1442
1443 for (String listenerClassName : listenerClassNames) {
1444 listenersList.add((ModelListener<TagsEntry>)Class.forName(
1445 listenerClassName).newInstance());
1446 }
1447
1448 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1449 }
1450 catch (Exception e) {
1451 _log.error(e);
1452 }
1453 }
1454
1455 containsTagsAsset = new ContainsTagsAsset(this);
1456
1457 addTagsAsset = new AddTagsAsset(this);
1458 clearTagsAssets = new ClearTagsAssets(this);
1459 removeTagsAsset = new RemoveTagsAsset(this);
1460 }
1461
1462 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1463 protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1464 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1465 protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1466 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1467 protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1468 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1469 protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1470 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence.impl")
1471 protected com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence tagsVocabularyPersistence;
1472 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1473 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1474 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1475 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1476 protected ContainsTagsAsset containsTagsAsset;
1477 protected AddTagsAsset addTagsAsset;
1478 protected ClearTagsAssets clearTagsAssets;
1479 protected RemoveTagsAsset removeTagsAsset;
1480
1481 protected class ContainsTagsAsset {
1482 protected ContainsTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1483 super();
1484
1485 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1486 _SQL_CONTAINSTAGSASSET,
1487 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1488 }
1489
1490 protected boolean contains(long entryId, long assetId) {
1491 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1492 new Long(entryId), new Long(assetId)
1493 });
1494
1495 if (results.size() > 0) {
1496 Integer count = results.get(0);
1497
1498 if (count.intValue() > 0) {
1499 return true;
1500 }
1501 }
1502
1503 return false;
1504 }
1505
1506 private MappingSqlQuery _mappingSqlQuery;
1507 }
1508
1509 protected class AddTagsAsset {
1510 protected AddTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1511 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1512 "INSERT INTO TagsAssets_TagsEntries (entryId, assetId) VALUES (?, ?)",
1513 new int[] { Types.BIGINT, Types.BIGINT });
1514 _persistenceImpl = persistenceImpl;
1515 }
1516
1517 protected void add(long entryId, long assetId)
1518 throws SystemException {
1519 if (!_persistenceImpl.containsTagsAsset.contains(entryId, assetId)) {
1520 ModelListener<com.liferay.portlet.tags.model.TagsAsset>[] tagsAssetListeners =
1521 tagsAssetPersistence.getListeners();
1522
1523 for (ModelListener<TagsEntry> listener : listeners) {
1524 listener.onBeforeAddAssociation(entryId,
1525 com.liferay.portlet.tags.model.TagsAsset.class.getName(),
1526 assetId);
1527 }
1528
1529 for (ModelListener<com.liferay.portlet.tags.model.TagsAsset> listener : tagsAssetListeners) {
1530 listener.onBeforeAddAssociation(assetId,
1531 TagsEntry.class.getName(), entryId);
1532 }
1533
1534 _sqlUpdate.update(new Object[] {
1535 new Long(entryId), new Long(assetId)
1536 });
1537
1538 for (ModelListener<TagsEntry> listener : listeners) {
1539 listener.onAfterAddAssociation(entryId,
1540 com.liferay.portlet.tags.model.TagsAsset.class.getName(),
1541 assetId);
1542 }
1543
1544 for (ModelListener<com.liferay.portlet.tags.model.TagsAsset> listener : tagsAssetListeners) {
1545 listener.onAfterAddAssociation(assetId,
1546 TagsEntry.class.getName(), entryId);
1547 }
1548 }
1549 }
1550
1551 private SqlUpdate _sqlUpdate;
1552 private TagsEntryPersistenceImpl _persistenceImpl;
1553 }
1554
1555 protected class ClearTagsAssets {
1556 protected ClearTagsAssets(TagsEntryPersistenceImpl persistenceImpl) {
1557 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1558 "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ?",
1559 new int[] { Types.BIGINT });
1560 }
1561
1562 protected void clear(long entryId) throws SystemException {
1563 ModelListener<com.liferay.portlet.tags.model.TagsAsset>[] tagsAssetListeners =
1564 tagsAssetPersistence.getListeners();
1565
1566 List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets = null;
1567
1568 if ((listeners.length > 0) || (tagsAssetListeners.length > 0)) {
1569 tagsAssets = getTagsAssets(entryId);
1570
1571 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1572 for (ModelListener<TagsEntry> listener : listeners) {
1573 listener.onBeforeRemoveAssociation(entryId,
1574 com.liferay.portlet.tags.model.TagsAsset.class.getName(),
1575 tagsAsset.getPrimaryKey());
1576 }
1577
1578 for (ModelListener<com.liferay.portlet.tags.model.TagsAsset> listener : tagsAssetListeners) {
1579 listener.onBeforeRemoveAssociation(tagsAsset.getPrimaryKey(),
1580 TagsEntry.class.getName(), entryId);
1581 }
1582 }
1583 }
1584
1585 _sqlUpdate.update(new Object[] { new Long(entryId) });
1586
1587 if ((listeners.length > 0) || (tagsAssetListeners.length > 0)) {
1588 for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1589 for (ModelListener<TagsEntry> listener : listeners) {
1590 listener.onAfterRemoveAssociation(entryId,
1591 com.liferay.portlet.tags.model.TagsAsset.class.getName(),
1592 tagsAsset.getPrimaryKey());
1593 }
1594
1595 for (ModelListener<com.liferay.portlet.tags.model.TagsAsset> listener : tagsAssetListeners) {
1596 listener.onBeforeRemoveAssociation(tagsAsset.getPrimaryKey(),
1597 TagsEntry.class.getName(), entryId);
1598 }
1599 }
1600 }
1601 }
1602
1603 private SqlUpdate _sqlUpdate;
1604 }
1605
1606 protected class RemoveTagsAsset {
1607 protected RemoveTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1608 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1609 "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?",
1610 new int[] { Types.BIGINT, Types.BIGINT });
1611 _persistenceImpl = persistenceImpl;
1612 }
1613
1614 protected void remove(long entryId, long assetId)
1615 throws SystemException {
1616 if (_persistenceImpl.containsTagsAsset.contains(entryId, assetId)) {
1617 ModelListener<com.liferay.portlet.tags.model.TagsAsset>[] tagsAssetListeners =
1618 tagsAssetPersistence.getListeners();
1619
1620 for (ModelListener<TagsEntry> listener : listeners) {
1621 listener.onBeforeRemoveAssociation(entryId,
1622 com.liferay.portlet.tags.model.TagsAsset.class.getName(),
1623 assetId);
1624 }
1625
1626 for (ModelListener<com.liferay.portlet.tags.model.TagsAsset> listener : tagsAssetListeners) {
1627 listener.onBeforeRemoveAssociation(assetId,
1628 TagsEntry.class.getName(), entryId);
1629 }
1630
1631 _sqlUpdate.update(new Object[] {
1632 new Long(entryId), new Long(assetId)
1633 });
1634
1635 for (ModelListener<TagsEntry> listener : listeners) {
1636 listener.onAfterRemoveAssociation(entryId,
1637 com.liferay.portlet.tags.model.TagsAsset.class.getName(),
1638 assetId);
1639 }
1640
1641 for (ModelListener<com.liferay.portlet.tags.model.TagsAsset> listener : tagsAssetListeners) {
1642 listener.onAfterRemoveAssociation(assetId,
1643 TagsEntry.class.getName(), entryId);
1644 }
1645 }
1646 }
1647
1648 private SqlUpdate _sqlUpdate;
1649 private TagsEntryPersistenceImpl _persistenceImpl;
1650 }
1651
1652 private static final String _SQL_GETTAGSASSETS = "SELECT {TagsAsset.*} FROM TagsAsset INNER JOIN TagsAssets_TagsEntries ON (TagsAssets_TagsEntries.assetId = TagsAsset.assetId) WHERE (TagsAssets_TagsEntries.entryId = ?)";
1653 private static final String _SQL_GETTAGSASSETSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ?";
1654 private static final String _SQL_CONTAINSTAGSASSET = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?";
1655 private static Log _log = LogFactoryUtil.getLog(TagsEntryPersistenceImpl.class);
1656}