1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchServiceComponentException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32 import com.liferay.portal.kernel.dao.orm.FinderPath;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.Session;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.OrderByComparator;
41 import com.liferay.portal.kernel.util.StringPool;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.kernel.util.Validator;
44 import com.liferay.portal.model.ModelListener;
45 import com.liferay.portal.model.ServiceComponent;
46 import com.liferay.portal.model.impl.ServiceComponentImpl;
47 import com.liferay.portal.model.impl.ServiceComponentModelImpl;
48 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.List;
53
54
60 public class ServiceComponentPersistenceImpl extends BasePersistenceImpl
61 implements ServiceComponentPersistence {
62 public static final String FINDER_CLASS_NAME_ENTITY = ServiceComponentImpl.class.getName();
63 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
64 ".List";
65 public static final FinderPath FINDER_PATH_FIND_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
66 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
67 FINDER_CLASS_NAME_LIST, "findByBuildNamespace",
68 new String[] { String.class.getName() });
69 public static final FinderPath FINDER_PATH_FIND_BY_OBC_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
70 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
71 FINDER_CLASS_NAME_LIST, "findByBuildNamespace",
72 new String[] {
73 String.class.getName(),
74
75 "java.lang.Integer", "java.lang.Integer",
76 "com.liferay.portal.kernel.util.OrderByComparator"
77 });
78 public static final FinderPath FINDER_PATH_COUNT_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
79 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
80 FINDER_CLASS_NAME_LIST, "countByBuildNamespace",
81 new String[] { String.class.getName() });
82 public static final FinderPath FINDER_PATH_FETCH_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
83 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
84 FINDER_CLASS_NAME_ENTITY, "fetchByBNS_BNU",
85 new String[] { String.class.getName(), Long.class.getName() });
86 public static final FinderPath FINDER_PATH_COUNT_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
87 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
88 FINDER_CLASS_NAME_LIST, "countByBNS_BNU",
89 new String[] { String.class.getName(), Long.class.getName() });
90 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
91 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
92 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
93 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
94 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
95 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
96
97 public void cacheResult(ServiceComponent serviceComponent) {
98 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
99 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
100 serviceComponent);
101
102 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
103 new Object[] {
104 serviceComponent.getBuildNamespace(),
105 new Long(serviceComponent.getBuildNumber())
106 }, serviceComponent);
107 }
108
109 public void cacheResult(List<ServiceComponent> serviceComponents) {
110 for (ServiceComponent serviceComponent : serviceComponents) {
111 if (EntityCacheUtil.getResult(
112 ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
113 ServiceComponentImpl.class,
114 serviceComponent.getPrimaryKey(), this) == null) {
115 cacheResult(serviceComponent);
116 }
117 }
118 }
119
120 public void clearCache() {
121 CacheRegistry.clear(ServiceComponentImpl.class.getName());
122 EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
123 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
124 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
125 }
126
127 public ServiceComponent create(long serviceComponentId) {
128 ServiceComponent serviceComponent = new ServiceComponentImpl();
129
130 serviceComponent.setNew(true);
131 serviceComponent.setPrimaryKey(serviceComponentId);
132
133 return serviceComponent;
134 }
135
136 public ServiceComponent remove(long serviceComponentId)
137 throws NoSuchServiceComponentException, SystemException {
138 Session session = null;
139
140 try {
141 session = openSession();
142
143 ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
144 new Long(serviceComponentId));
145
146 if (serviceComponent == null) {
147 if (_log.isWarnEnabled()) {
148 _log.warn(
149 "No ServiceComponent exists with the primary key " +
150 serviceComponentId);
151 }
152
153 throw new NoSuchServiceComponentException(
154 "No ServiceComponent exists with the primary key " +
155 serviceComponentId);
156 }
157
158 return remove(serviceComponent);
159 }
160 catch (NoSuchServiceComponentException nsee) {
161 throw nsee;
162 }
163 catch (Exception e) {
164 throw processException(e);
165 }
166 finally {
167 closeSession(session);
168 }
169 }
170
171 public ServiceComponent remove(ServiceComponent serviceComponent)
172 throws SystemException {
173 for (ModelListener<ServiceComponent> listener : listeners) {
174 listener.onBeforeRemove(serviceComponent);
175 }
176
177 serviceComponent = removeImpl(serviceComponent);
178
179 for (ModelListener<ServiceComponent> listener : listeners) {
180 listener.onAfterRemove(serviceComponent);
181 }
182
183 return serviceComponent;
184 }
185
186 protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
187 throws SystemException {
188 Session session = null;
189
190 try {
191 session = openSession();
192
193 if (serviceComponent.isCachedModel() ||
194 BatchSessionUtil.isEnabled()) {
195 Object staleObject = session.get(ServiceComponentImpl.class,
196 serviceComponent.getPrimaryKeyObj());
197
198 if (staleObject != null) {
199 session.evict(staleObject);
200 }
201 }
202
203 session.delete(serviceComponent);
204
205 session.flush();
206 }
207 catch (Exception e) {
208 throw processException(e);
209 }
210 finally {
211 closeSession(session);
212 }
213
214 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
215
216 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
217
218 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
219 new Object[] {
220 serviceComponentModelImpl.getOriginalBuildNamespace(),
221 new Long(serviceComponentModelImpl.getOriginalBuildNumber())
222 });
223
224 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
225 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
226
227 return serviceComponent;
228 }
229
230
233 public ServiceComponent update(ServiceComponent serviceComponent)
234 throws SystemException {
235 if (_log.isWarnEnabled()) {
236 _log.warn(
237 "Using the deprecated update(ServiceComponent serviceComponent) method. Use update(ServiceComponent serviceComponent, boolean merge) instead.");
238 }
239
240 return update(serviceComponent, false);
241 }
242
243
256 public ServiceComponent update(ServiceComponent serviceComponent,
257 boolean merge) throws SystemException {
258 boolean isNew = serviceComponent.isNew();
259
260 for (ModelListener<ServiceComponent> listener : listeners) {
261 if (isNew) {
262 listener.onBeforeCreate(serviceComponent);
263 }
264 else {
265 listener.onBeforeUpdate(serviceComponent);
266 }
267 }
268
269 serviceComponent = updateImpl(serviceComponent, merge);
270
271 for (ModelListener<ServiceComponent> listener : listeners) {
272 if (isNew) {
273 listener.onAfterCreate(serviceComponent);
274 }
275 else {
276 listener.onAfterUpdate(serviceComponent);
277 }
278 }
279
280 return serviceComponent;
281 }
282
283 public ServiceComponent updateImpl(
284 com.liferay.portal.model.ServiceComponent serviceComponent,
285 boolean merge) throws SystemException {
286 boolean isNew = serviceComponent.isNew();
287
288 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
289
290 Session session = null;
291
292 try {
293 session = openSession();
294
295 BatchSessionUtil.update(session, serviceComponent, merge);
296
297 serviceComponent.setNew(false);
298 }
299 catch (Exception e) {
300 throw processException(e);
301 }
302 finally {
303 closeSession(session);
304 }
305
306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
307
308 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
309 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
310 serviceComponent);
311
312 if (!isNew &&
313 (!Validator.equals(serviceComponent.getBuildNamespace(),
314 serviceComponentModelImpl.getOriginalBuildNamespace()) ||
315 (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
316 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
317 new Object[] {
318 serviceComponentModelImpl.getOriginalBuildNamespace(),
319 new Long(serviceComponentModelImpl.getOriginalBuildNumber())
320 });
321 }
322
323 if (isNew ||
324 (!Validator.equals(serviceComponent.getBuildNamespace(),
325 serviceComponentModelImpl.getOriginalBuildNamespace()) ||
326 (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
327 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
328 new Object[] {
329 serviceComponent.getBuildNamespace(),
330 new Long(serviceComponent.getBuildNumber())
331 }, serviceComponent);
332 }
333
334 return serviceComponent;
335 }
336
337 public ServiceComponent findByPrimaryKey(long serviceComponentId)
338 throws NoSuchServiceComponentException, SystemException {
339 ServiceComponent serviceComponent = fetchByPrimaryKey(serviceComponentId);
340
341 if (serviceComponent == null) {
342 if (_log.isWarnEnabled()) {
343 _log.warn("No ServiceComponent exists with the primary key " +
344 serviceComponentId);
345 }
346
347 throw new NoSuchServiceComponentException(
348 "No ServiceComponent exists with the primary key " +
349 serviceComponentId);
350 }
351
352 return serviceComponent;
353 }
354
355 public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
356 throws SystemException {
357 ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
358 ServiceComponentImpl.class, serviceComponentId, this);
359
360 if (serviceComponent == null) {
361 Session session = null;
362
363 try {
364 session = openSession();
365
366 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
367 new Long(serviceComponentId));
368 }
369 catch (Exception e) {
370 throw processException(e);
371 }
372 finally {
373 if (serviceComponent != null) {
374 cacheResult(serviceComponent);
375 }
376
377 closeSession(session);
378 }
379 }
380
381 return serviceComponent;
382 }
383
384 public List<ServiceComponent> findByBuildNamespace(String buildNamespace)
385 throws SystemException {
386 Object[] finderArgs = new Object[] { buildNamespace };
387
388 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
389 finderArgs, this);
390
391 if (list == null) {
392 Session session = null;
393
394 try {
395 session = openSession();
396
397 StringBuilder query = new StringBuilder();
398
399 query.append(
400 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
401
402 if (buildNamespace == null) {
403 query.append("buildNamespace IS NULL");
404 }
405 else {
406 query.append("buildNamespace = ?");
407 }
408
409 query.append(" ");
410
411 query.append("ORDER BY ");
412
413 query.append("buildNamespace DESC, ");
414 query.append("buildNumber DESC");
415
416 Query q = session.createQuery(query.toString());
417
418 QueryPos qPos = QueryPos.getInstance(q);
419
420 if (buildNamespace != null) {
421 qPos.add(buildNamespace);
422 }
423
424 list = q.list();
425 }
426 catch (Exception e) {
427 throw processException(e);
428 }
429 finally {
430 if (list == null) {
431 list = new ArrayList<ServiceComponent>();
432 }
433
434 cacheResult(list);
435
436 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
437 finderArgs, list);
438
439 closeSession(session);
440 }
441 }
442
443 return list;
444 }
445
446 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
447 int start, int end) throws SystemException {
448 return findByBuildNamespace(buildNamespace, start, end, null);
449 }
450
451 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
452 int start, int end, OrderByComparator obc) throws SystemException {
453 Object[] finderArgs = new Object[] {
454 buildNamespace,
455
456 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
457 };
458
459 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_BUILDNAMESPACE,
460 finderArgs, this);
461
462 if (list == null) {
463 Session session = null;
464
465 try {
466 session = openSession();
467
468 StringBuilder query = new StringBuilder();
469
470 query.append(
471 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
472
473 if (buildNamespace == null) {
474 query.append("buildNamespace IS NULL");
475 }
476 else {
477 query.append("buildNamespace = ?");
478 }
479
480 query.append(" ");
481
482 if (obc != null) {
483 query.append("ORDER BY ");
484 query.append(obc.getOrderBy());
485 }
486
487 else {
488 query.append("ORDER BY ");
489
490 query.append("buildNamespace DESC, ");
491 query.append("buildNumber DESC");
492 }
493
494 Query q = session.createQuery(query.toString());
495
496 QueryPos qPos = QueryPos.getInstance(q);
497
498 if (buildNamespace != null) {
499 qPos.add(buildNamespace);
500 }
501
502 list = (List<ServiceComponent>)QueryUtil.list(q, getDialect(),
503 start, end);
504 }
505 catch (Exception e) {
506 throw processException(e);
507 }
508 finally {
509 if (list == null) {
510 list = new ArrayList<ServiceComponent>();
511 }
512
513 cacheResult(list);
514
515 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_BUILDNAMESPACE,
516 finderArgs, list);
517
518 closeSession(session);
519 }
520 }
521
522 return list;
523 }
524
525 public ServiceComponent findByBuildNamespace_First(String buildNamespace,
526 OrderByComparator obc)
527 throws NoSuchServiceComponentException, SystemException {
528 List<ServiceComponent> list = findByBuildNamespace(buildNamespace, 0,
529 1, obc);
530
531 if (list.isEmpty()) {
532 StringBuilder msg = new StringBuilder();
533
534 msg.append("No ServiceComponent exists with the key {");
535
536 msg.append("buildNamespace=" + buildNamespace);
537
538 msg.append(StringPool.CLOSE_CURLY_BRACE);
539
540 throw new NoSuchServiceComponentException(msg.toString());
541 }
542 else {
543 return list.get(0);
544 }
545 }
546
547 public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
548 OrderByComparator obc)
549 throws NoSuchServiceComponentException, SystemException {
550 int count = countByBuildNamespace(buildNamespace);
551
552 List<ServiceComponent> list = findByBuildNamespace(buildNamespace,
553 count - 1, count, obc);
554
555 if (list.isEmpty()) {
556 StringBuilder msg = new StringBuilder();
557
558 msg.append("No ServiceComponent exists with the key {");
559
560 msg.append("buildNamespace=" + buildNamespace);
561
562 msg.append(StringPool.CLOSE_CURLY_BRACE);
563
564 throw new NoSuchServiceComponentException(msg.toString());
565 }
566 else {
567 return list.get(0);
568 }
569 }
570
571 public ServiceComponent[] findByBuildNamespace_PrevAndNext(
572 long serviceComponentId, String buildNamespace, OrderByComparator obc)
573 throws NoSuchServiceComponentException, SystemException {
574 ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
575
576 int count = countByBuildNamespace(buildNamespace);
577
578 Session session = null;
579
580 try {
581 session = openSession();
582
583 StringBuilder query = new StringBuilder();
584
585 query.append(
586 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
587
588 if (buildNamespace == null) {
589 query.append("buildNamespace IS NULL");
590 }
591 else {
592 query.append("buildNamespace = ?");
593 }
594
595 query.append(" ");
596
597 if (obc != null) {
598 query.append("ORDER BY ");
599 query.append(obc.getOrderBy());
600 }
601
602 else {
603 query.append("ORDER BY ");
604
605 query.append("buildNamespace DESC, ");
606 query.append("buildNumber DESC");
607 }
608
609 Query q = session.createQuery(query.toString());
610
611 QueryPos qPos = QueryPos.getInstance(q);
612
613 if (buildNamespace != null) {
614 qPos.add(buildNamespace);
615 }
616
617 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
618 serviceComponent);
619
620 ServiceComponent[] array = new ServiceComponentImpl[3];
621
622 array[0] = (ServiceComponent)objArray[0];
623 array[1] = (ServiceComponent)objArray[1];
624 array[2] = (ServiceComponent)objArray[2];
625
626 return array;
627 }
628 catch (Exception e) {
629 throw processException(e);
630 }
631 finally {
632 closeSession(session);
633 }
634 }
635
636 public ServiceComponent findByBNS_BNU(String buildNamespace,
637 long buildNumber)
638 throws NoSuchServiceComponentException, SystemException {
639 ServiceComponent serviceComponent = fetchByBNS_BNU(buildNamespace,
640 buildNumber);
641
642 if (serviceComponent == null) {
643 StringBuilder msg = new StringBuilder();
644
645 msg.append("No ServiceComponent exists with the key {");
646
647 msg.append("buildNamespace=" + buildNamespace);
648
649 msg.append(", ");
650 msg.append("buildNumber=" + buildNumber);
651
652 msg.append(StringPool.CLOSE_CURLY_BRACE);
653
654 if (_log.isWarnEnabled()) {
655 _log.warn(msg.toString());
656 }
657
658 throw new NoSuchServiceComponentException(msg.toString());
659 }
660
661 return serviceComponent;
662 }
663
664 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
665 long buildNumber) throws SystemException {
666 return fetchByBNS_BNU(buildNamespace, buildNumber, true);
667 }
668
669 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
670 long buildNumber, boolean retrieveFromCache) throws SystemException {
671 Object[] finderArgs = new Object[] { buildNamespace, new Long(buildNumber) };
672
673 Object result = null;
674
675 if (retrieveFromCache) {
676 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_BNS_BNU,
677 finderArgs, this);
678 }
679
680 if (result == null) {
681 Session session = null;
682
683 try {
684 session = openSession();
685
686 StringBuilder query = new StringBuilder();
687
688 query.append(
689 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
690
691 if (buildNamespace == null) {
692 query.append("buildNamespace IS NULL");
693 }
694 else {
695 query.append("buildNamespace = ?");
696 }
697
698 query.append(" AND ");
699
700 query.append("buildNumber = ?");
701
702 query.append(" ");
703
704 query.append("ORDER BY ");
705
706 query.append("buildNamespace DESC, ");
707 query.append("buildNumber DESC");
708
709 Query q = session.createQuery(query.toString());
710
711 QueryPos qPos = QueryPos.getInstance(q);
712
713 if (buildNamespace != null) {
714 qPos.add(buildNamespace);
715 }
716
717 qPos.add(buildNumber);
718
719 List<ServiceComponent> list = q.list();
720
721 result = list;
722
723 ServiceComponent serviceComponent = null;
724
725 if (list.isEmpty()) {
726 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
727 finderArgs, list);
728 }
729 else {
730 serviceComponent = list.get(0);
731
732 cacheResult(serviceComponent);
733
734 if ((serviceComponent.getBuildNamespace() == null) ||
735 !serviceComponent.getBuildNamespace()
736 .equals(buildNamespace) ||
737 (serviceComponent.getBuildNumber() != buildNumber)) {
738 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
739 finderArgs, serviceComponent);
740 }
741 }
742
743 return serviceComponent;
744 }
745 catch (Exception e) {
746 throw processException(e);
747 }
748 finally {
749 if (result == null) {
750 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
751 finderArgs, new ArrayList<ServiceComponent>());
752 }
753
754 closeSession(session);
755 }
756 }
757 else {
758 if (result instanceof List) {
759 return null;
760 }
761 else {
762 return (ServiceComponent)result;
763 }
764 }
765 }
766
767 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
768 throws SystemException {
769 Session session = null;
770
771 try {
772 session = openSession();
773
774 dynamicQuery.compile(session);
775
776 return dynamicQuery.list();
777 }
778 catch (Exception e) {
779 throw processException(e);
780 }
781 finally {
782 closeSession(session);
783 }
784 }
785
786 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
787 int start, int end) throws SystemException {
788 Session session = null;
789
790 try {
791 session = openSession();
792
793 dynamicQuery.setLimit(start, end);
794
795 dynamicQuery.compile(session);
796
797 return dynamicQuery.list();
798 }
799 catch (Exception e) {
800 throw processException(e);
801 }
802 finally {
803 closeSession(session);
804 }
805 }
806
807 public List<ServiceComponent> findAll() throws SystemException {
808 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
809 }
810
811 public List<ServiceComponent> findAll(int start, int end)
812 throws SystemException {
813 return findAll(start, end, null);
814 }
815
816 public List<ServiceComponent> findAll(int start, int end,
817 OrderByComparator obc) throws SystemException {
818 Object[] finderArgs = new Object[] {
819 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
820 };
821
822 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
823 finderArgs, this);
824
825 if (list == null) {
826 Session session = null;
827
828 try {
829 session = openSession();
830
831 StringBuilder query = new StringBuilder();
832
833 query.append("FROM com.liferay.portal.model.ServiceComponent ");
834
835 if (obc != null) {
836 query.append("ORDER BY ");
837 query.append(obc.getOrderBy());
838 }
839
840 else {
841 query.append("ORDER BY ");
842
843 query.append("buildNamespace DESC, ");
844 query.append("buildNumber DESC");
845 }
846
847 Query q = session.createQuery(query.toString());
848
849 if (obc == null) {
850 list = (List<ServiceComponent>)QueryUtil.list(q,
851 getDialect(), start, end, false);
852
853 Collections.sort(list);
854 }
855 else {
856 list = (List<ServiceComponent>)QueryUtil.list(q,
857 getDialect(), start, end);
858 }
859 }
860 catch (Exception e) {
861 throw processException(e);
862 }
863 finally {
864 if (list == null) {
865 list = new ArrayList<ServiceComponent>();
866 }
867
868 cacheResult(list);
869
870 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
871
872 closeSession(session);
873 }
874 }
875
876 return list;
877 }
878
879 public void removeByBuildNamespace(String buildNamespace)
880 throws SystemException {
881 for (ServiceComponent serviceComponent : findByBuildNamespace(
882 buildNamespace)) {
883 remove(serviceComponent);
884 }
885 }
886
887 public void removeByBNS_BNU(String buildNamespace, long buildNumber)
888 throws NoSuchServiceComponentException, SystemException {
889 ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
890 buildNumber);
891
892 remove(serviceComponent);
893 }
894
895 public void removeAll() throws SystemException {
896 for (ServiceComponent serviceComponent : findAll()) {
897 remove(serviceComponent);
898 }
899 }
900
901 public int countByBuildNamespace(String buildNamespace)
902 throws SystemException {
903 Object[] finderArgs = new Object[] { buildNamespace };
904
905 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
906 finderArgs, this);
907
908 if (count == null) {
909 Session session = null;
910
911 try {
912 session = openSession();
913
914 StringBuilder query = new StringBuilder();
915
916 query.append("SELECT COUNT(*) ");
917 query.append(
918 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
919
920 if (buildNamespace == null) {
921 query.append("buildNamespace IS NULL");
922 }
923 else {
924 query.append("buildNamespace = ?");
925 }
926
927 query.append(" ");
928
929 Query q = session.createQuery(query.toString());
930
931 QueryPos qPos = QueryPos.getInstance(q);
932
933 if (buildNamespace != null) {
934 qPos.add(buildNamespace);
935 }
936
937 count = (Long)q.uniqueResult();
938 }
939 catch (Exception e) {
940 throw processException(e);
941 }
942 finally {
943 if (count == null) {
944 count = Long.valueOf(0);
945 }
946
947 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
948 finderArgs, count);
949
950 closeSession(session);
951 }
952 }
953
954 return count.intValue();
955 }
956
957 public int countByBNS_BNU(String buildNamespace, long buildNumber)
958 throws SystemException {
959 Object[] finderArgs = new Object[] { buildNamespace, new Long(buildNumber) };
960
961 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BNS_BNU,
962 finderArgs, this);
963
964 if (count == null) {
965 Session session = null;
966
967 try {
968 session = openSession();
969
970 StringBuilder query = new StringBuilder();
971
972 query.append("SELECT COUNT(*) ");
973 query.append(
974 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
975
976 if (buildNamespace == null) {
977 query.append("buildNamespace IS NULL");
978 }
979 else {
980 query.append("buildNamespace = ?");
981 }
982
983 query.append(" AND ");
984
985 query.append("buildNumber = ?");
986
987 query.append(" ");
988
989 Query q = session.createQuery(query.toString());
990
991 QueryPos qPos = QueryPos.getInstance(q);
992
993 if (buildNamespace != null) {
994 qPos.add(buildNamespace);
995 }
996
997 qPos.add(buildNumber);
998
999 count = (Long)q.uniqueResult();
1000 }
1001 catch (Exception e) {
1002 throw processException(e);
1003 }
1004 finally {
1005 if (count == null) {
1006 count = Long.valueOf(0);
1007 }
1008
1009 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU,
1010 finderArgs, count);
1011
1012 closeSession(session);
1013 }
1014 }
1015
1016 return count.intValue();
1017 }
1018
1019 public int countAll() throws SystemException {
1020 Object[] finderArgs = new Object[0];
1021
1022 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1023 finderArgs, this);
1024
1025 if (count == null) {
1026 Session session = null;
1027
1028 try {
1029 session = openSession();
1030
1031 Query q = session.createQuery(
1032 "SELECT COUNT(*) FROM com.liferay.portal.model.ServiceComponent");
1033
1034 count = (Long)q.uniqueResult();
1035 }
1036 catch (Exception e) {
1037 throw processException(e);
1038 }
1039 finally {
1040 if (count == null) {
1041 count = Long.valueOf(0);
1042 }
1043
1044 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1045 count);
1046
1047 closeSession(session);
1048 }
1049 }
1050
1051 return count.intValue();
1052 }
1053
1054 public void afterPropertiesSet() {
1055 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1056 com.liferay.portal.util.PropsUtil.get(
1057 "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1058
1059 if (listenerClassNames.length > 0) {
1060 try {
1061 List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1062
1063 for (String listenerClassName : listenerClassNames) {
1064 listenersList.add((ModelListener<ServiceComponent>)Class.forName(
1065 listenerClassName).newInstance());
1066 }
1067
1068 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1069 }
1070 catch (Exception e) {
1071 _log.error(e);
1072 }
1073 }
1074 }
1075
1076 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1077 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1078 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1079 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1080 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1081 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1082 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1083 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1084 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1085 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1086 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1087 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1088 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1089 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1090 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1091 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1092 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1093 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1094 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1095 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1096 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1097 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1098 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1099 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1100 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1101 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1102 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1103 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1104 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1105 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1106 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1107 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1108 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1109 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1110 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1111 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1112 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1113 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1114 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1115 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1116 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1117 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1118 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1119 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1120 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1121 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1122 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1123 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1124 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1125 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1126 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1127 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1128 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1129 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1130 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1131 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1132 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1133 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1134 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1135 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1136 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1137 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1138 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1139 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1140 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1141 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1142 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1143 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1144 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1145 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1146 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1147 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1148 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1149 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1150 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1151 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1152 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1153 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1154 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1155 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1156 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1157 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1158 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1159 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1160 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1161 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1162 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1163 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1164 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1165 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1166 private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1167}