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