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