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