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