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