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