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