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