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