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