001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchServiceComponentException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.ServiceComponent;
040 import com.liferay.portal.model.impl.ServiceComponentImpl;
041 import com.liferay.portal.model.impl.ServiceComponentModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
066 public class ServiceComponentPersistenceImpl extends BasePersistenceImpl<ServiceComponent>
067 implements ServiceComponentPersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = ServiceComponentImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FIND_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
072 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
073 FINDER_CLASS_NAME_LIST, "findByBuildNamespace",
074 new String[] {
075 String.class.getName(),
076
077 "java.lang.Integer", "java.lang.Integer",
078 "com.liferay.portal.kernel.util.OrderByComparator"
079 });
080 public static final FinderPath FINDER_PATH_COUNT_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
081 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
082 FINDER_CLASS_NAME_LIST, "countByBuildNamespace",
083 new String[] { String.class.getName() });
084 public static final FinderPath FINDER_PATH_FETCH_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
085 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
086 FINDER_CLASS_NAME_ENTITY, "fetchByBNS_BNU",
087 new String[] { String.class.getName(), Long.class.getName() });
088 public static final FinderPath FINDER_PATH_COUNT_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
089 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_LIST, "countByBNS_BNU",
091 new String[] { String.class.getName(), Long.class.getName() });
092 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
093 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
095 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
096 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
097 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
098
099
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
121 public void cacheResult(List<ServiceComponent> serviceComponents) {
122 for (ServiceComponent serviceComponent : serviceComponents) {
123 if (EntityCacheUtil.getResult(
124 ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
125 ServiceComponentImpl.class,
126 serviceComponent.getPrimaryKey(), this) == null) {
127 cacheResult(serviceComponent);
128 }
129 }
130 }
131
132
139 public void clearCache() {
140 CacheRegistryUtil.clear(ServiceComponentImpl.class.getName());
141 EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
142 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
143 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
144 }
145
146
153 public void clearCache(ServiceComponent serviceComponent) {
154 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
155 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
156
157 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
158 new Object[] {
159 serviceComponent.getBuildNamespace(),
160 new Long(serviceComponent.getBuildNumber())
161 });
162 }
163
164
170 public ServiceComponent create(long serviceComponentId) {
171 ServiceComponent serviceComponent = new ServiceComponentImpl();
172
173 serviceComponent.setNew(true);
174 serviceComponent.setPrimaryKey(serviceComponentId);
175
176 return serviceComponent;
177 }
178
179
187 public ServiceComponent remove(Serializable primaryKey)
188 throws NoSuchModelException, SystemException {
189 return remove(((Long)primaryKey).longValue());
190 }
191
192
200 public ServiceComponent remove(long serviceComponentId)
201 throws NoSuchServiceComponentException, SystemException {
202 Session session = null;
203
204 try {
205 session = openSession();
206
207 ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
208 new Long(serviceComponentId));
209
210 if (serviceComponent == null) {
211 if (_log.isWarnEnabled()) {
212 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
213 serviceComponentId);
214 }
215
216 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
217 serviceComponentId);
218 }
219
220 return remove(serviceComponent);
221 }
222 catch (NoSuchServiceComponentException nsee) {
223 throw nsee;
224 }
225 catch (Exception e) {
226 throw processException(e);
227 }
228 finally {
229 closeSession(session);
230 }
231 }
232
233 protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
234 throws SystemException {
235 serviceComponent = toUnwrappedModel(serviceComponent);
236
237 Session session = null;
238
239 try {
240 session = openSession();
241
242 BatchSessionUtil.delete(session, serviceComponent);
243 }
244 catch (Exception e) {
245 throw processException(e);
246 }
247 finally {
248 closeSession(session);
249 }
250
251 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252
253 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
254
255 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
256 new Object[] {
257 serviceComponentModelImpl.getOriginalBuildNamespace(),
258 new Long(serviceComponentModelImpl.getOriginalBuildNumber())
259 });
260
261 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
262 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
263
264 return serviceComponent;
265 }
266
267 public ServiceComponent updateImpl(
268 com.liferay.portal.model.ServiceComponent serviceComponent,
269 boolean merge) throws SystemException {
270 serviceComponent = toUnwrappedModel(serviceComponent);
271
272 boolean isNew = serviceComponent.isNew();
273
274 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
275
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 BatchSessionUtil.update(session, serviceComponent, merge);
282
283 serviceComponent.setNew(false);
284 }
285 catch (Exception e) {
286 throw processException(e);
287 }
288 finally {
289 closeSession(session);
290 }
291
292 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
293
294 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
295 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
296 serviceComponent);
297
298 if (!isNew &&
299 (!Validator.equals(serviceComponent.getBuildNamespace(),
300 serviceComponentModelImpl.getOriginalBuildNamespace()) ||
301 (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
302 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
303 new Object[] {
304 serviceComponentModelImpl.getOriginalBuildNamespace(),
305 new Long(serviceComponentModelImpl.getOriginalBuildNumber())
306 });
307 }
308
309 if (isNew ||
310 (!Validator.equals(serviceComponent.getBuildNamespace(),
311 serviceComponentModelImpl.getOriginalBuildNamespace()) ||
312 (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
313 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
314 new Object[] {
315 serviceComponent.getBuildNamespace(),
316 new Long(serviceComponent.getBuildNumber())
317 }, serviceComponent);
318 }
319
320 return serviceComponent;
321 }
322
323 protected ServiceComponent toUnwrappedModel(
324 ServiceComponent serviceComponent) {
325 if (serviceComponent instanceof ServiceComponentImpl) {
326 return serviceComponent;
327 }
328
329 ServiceComponentImpl serviceComponentImpl = new ServiceComponentImpl();
330
331 serviceComponentImpl.setNew(serviceComponent.isNew());
332 serviceComponentImpl.setPrimaryKey(serviceComponent.getPrimaryKey());
333
334 serviceComponentImpl.setServiceComponentId(serviceComponent.getServiceComponentId());
335 serviceComponentImpl.setBuildNamespace(serviceComponent.getBuildNamespace());
336 serviceComponentImpl.setBuildNumber(serviceComponent.getBuildNumber());
337 serviceComponentImpl.setBuildDate(serviceComponent.getBuildDate());
338 serviceComponentImpl.setData(serviceComponent.getData());
339
340 return serviceComponentImpl;
341 }
342
343
351 public ServiceComponent findByPrimaryKey(Serializable primaryKey)
352 throws NoSuchModelException, SystemException {
353 return findByPrimaryKey(((Long)primaryKey).longValue());
354 }
355
356
364 public ServiceComponent findByPrimaryKey(long serviceComponentId)
365 throws NoSuchServiceComponentException, SystemException {
366 ServiceComponent serviceComponent = fetchByPrimaryKey(serviceComponentId);
367
368 if (serviceComponent == null) {
369 if (_log.isWarnEnabled()) {
370 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
371 serviceComponentId);
372 }
373
374 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
375 serviceComponentId);
376 }
377
378 return serviceComponent;
379 }
380
381
388 public ServiceComponent fetchByPrimaryKey(Serializable primaryKey)
389 throws SystemException {
390 return fetchByPrimaryKey(((Long)primaryKey).longValue());
391 }
392
393
400 public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
401 throws SystemException {
402 ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
403 ServiceComponentImpl.class, serviceComponentId, this);
404
405 if (serviceComponent == null) {
406 Session session = null;
407
408 try {
409 session = openSession();
410
411 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
412 new Long(serviceComponentId));
413 }
414 catch (Exception e) {
415 throw processException(e);
416 }
417 finally {
418 if (serviceComponent != null) {
419 cacheResult(serviceComponent);
420 }
421
422 closeSession(session);
423 }
424 }
425
426 return serviceComponent;
427 }
428
429
436 public List<ServiceComponent> findByBuildNamespace(String buildNamespace)
437 throws SystemException {
438 return findByBuildNamespace(buildNamespace, QueryUtil.ALL_POS,
439 QueryUtil.ALL_POS, null);
440 }
441
442
455 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
456 int start, int end) throws SystemException {
457 return findByBuildNamespace(buildNamespace, start, end, null);
458 }
459
460
474 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
475 int start, int end, OrderByComparator orderByComparator)
476 throws SystemException {
477 Object[] finderArgs = new Object[] {
478 buildNamespace,
479
480 String.valueOf(start), String.valueOf(end),
481 String.valueOf(orderByComparator)
482 };
483
484 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
485 finderArgs, this);
486
487 if (list == null) {
488 Session session = null;
489
490 try {
491 session = openSession();
492
493 StringBundler query = null;
494
495 if (orderByComparator != null) {
496 query = new StringBundler(3 +
497 (orderByComparator.getOrderByFields().length * 3));
498 }
499 else {
500 query = new StringBundler(3);
501 }
502
503 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
504
505 if (buildNamespace == null) {
506 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
507 }
508 else {
509 if (buildNamespace.equals(StringPool.BLANK)) {
510 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
511 }
512 else {
513 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
514 }
515 }
516
517 if (orderByComparator != null) {
518 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
519 orderByComparator);
520 }
521
522 else {
523 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
524 }
525
526 String sql = query.toString();
527
528 Query q = session.createQuery(sql);
529
530 QueryPos qPos = QueryPos.getInstance(q);
531
532 if (buildNamespace != null) {
533 qPos.add(buildNamespace);
534 }
535
536 list = (List<ServiceComponent>)QueryUtil.list(q, getDialect(),
537 start, end);
538 }
539 catch (Exception e) {
540 throw processException(e);
541 }
542 finally {
543 if (list == null) {
544 list = new ArrayList<ServiceComponent>();
545 }
546
547 cacheResult(list);
548
549 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
550 finderArgs, list);
551
552 closeSession(session);
553 }
554 }
555
556 return list;
557 }
558
559
572 public ServiceComponent findByBuildNamespace_First(String buildNamespace,
573 OrderByComparator orderByComparator)
574 throws NoSuchServiceComponentException, SystemException {
575 List<ServiceComponent> list = findByBuildNamespace(buildNamespace, 0,
576 1, orderByComparator);
577
578 if (list.isEmpty()) {
579 StringBundler msg = new StringBundler(4);
580
581 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
582
583 msg.append("buildNamespace=");
584 msg.append(buildNamespace);
585
586 msg.append(StringPool.CLOSE_CURLY_BRACE);
587
588 throw new NoSuchServiceComponentException(msg.toString());
589 }
590 else {
591 return list.get(0);
592 }
593 }
594
595
608 public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
609 OrderByComparator orderByComparator)
610 throws NoSuchServiceComponentException, SystemException {
611 int count = countByBuildNamespace(buildNamespace);
612
613 List<ServiceComponent> list = findByBuildNamespace(buildNamespace,
614 count - 1, count, orderByComparator);
615
616 if (list.isEmpty()) {
617 StringBundler msg = new StringBundler(4);
618
619 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
620
621 msg.append("buildNamespace=");
622 msg.append(buildNamespace);
623
624 msg.append(StringPool.CLOSE_CURLY_BRACE);
625
626 throw new NoSuchServiceComponentException(msg.toString());
627 }
628 else {
629 return list.get(0);
630 }
631 }
632
633
647 public ServiceComponent[] findByBuildNamespace_PrevAndNext(
648 long serviceComponentId, String buildNamespace,
649 OrderByComparator orderByComparator)
650 throws NoSuchServiceComponentException, SystemException {
651 ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
652
653 Session session = null;
654
655 try {
656 session = openSession();
657
658 ServiceComponent[] array = new ServiceComponentImpl[3];
659
660 array[0] = getByBuildNamespace_PrevAndNext(session,
661 serviceComponent, buildNamespace, orderByComparator, true);
662
663 array[1] = serviceComponent;
664
665 array[2] = getByBuildNamespace_PrevAndNext(session,
666 serviceComponent, buildNamespace, orderByComparator, false);
667
668 return array;
669 }
670 catch (Exception e) {
671 throw processException(e);
672 }
673 finally {
674 closeSession(session);
675 }
676 }
677
678 protected ServiceComponent getByBuildNamespace_PrevAndNext(
679 Session session, ServiceComponent serviceComponent,
680 String buildNamespace, OrderByComparator orderByComparator,
681 boolean previous) {
682 StringBundler query = null;
683
684 if (orderByComparator != null) {
685 query = new StringBundler(6 +
686 (orderByComparator.getOrderByFields().length * 6));
687 }
688 else {
689 query = new StringBundler(3);
690 }
691
692 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
693
694 if (buildNamespace == null) {
695 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
696 }
697 else {
698 if (buildNamespace.equals(StringPool.BLANK)) {
699 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
700 }
701 else {
702 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
703 }
704 }
705
706 if (orderByComparator != null) {
707 String[] orderByFields = orderByComparator.getOrderByFields();
708
709 if (orderByFields.length > 0) {
710 query.append(WHERE_AND);
711 }
712
713 for (int i = 0; i < orderByFields.length; i++) {
714 query.append(_ORDER_BY_ENTITY_ALIAS);
715 query.append(orderByFields[i]);
716
717 if ((i + 1) < orderByFields.length) {
718 if (orderByComparator.isAscending() ^ previous) {
719 query.append(WHERE_GREATER_THAN_HAS_NEXT);
720 }
721 else {
722 query.append(WHERE_LESSER_THAN_HAS_NEXT);
723 }
724 }
725 else {
726 if (orderByComparator.isAscending() ^ previous) {
727 query.append(WHERE_GREATER_THAN);
728 }
729 else {
730 query.append(WHERE_LESSER_THAN);
731 }
732 }
733 }
734
735 query.append(ORDER_BY_CLAUSE);
736
737 for (int i = 0; i < orderByFields.length; i++) {
738 query.append(_ORDER_BY_ENTITY_ALIAS);
739 query.append(orderByFields[i]);
740
741 if ((i + 1) < orderByFields.length) {
742 if (orderByComparator.isAscending() ^ previous) {
743 query.append(ORDER_BY_ASC_HAS_NEXT);
744 }
745 else {
746 query.append(ORDER_BY_DESC_HAS_NEXT);
747 }
748 }
749 else {
750 if (orderByComparator.isAscending() ^ previous) {
751 query.append(ORDER_BY_ASC);
752 }
753 else {
754 query.append(ORDER_BY_DESC);
755 }
756 }
757 }
758 }
759
760 else {
761 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
762 }
763
764 String sql = query.toString();
765
766 Query q = session.createQuery(sql);
767
768 q.setFirstResult(0);
769 q.setMaxResults(2);
770
771 QueryPos qPos = QueryPos.getInstance(q);
772
773 if (buildNamespace != null) {
774 qPos.add(buildNamespace);
775 }
776
777 if (orderByComparator != null) {
778 Object[] values = orderByComparator.getOrderByValues(serviceComponent);
779
780 for (Object value : values) {
781 qPos.add(value);
782 }
783 }
784
785 List<ServiceComponent> list = q.list();
786
787 if (list.size() == 2) {
788 return list.get(1);
789 }
790 else {
791 return null;
792 }
793 }
794
795
804 public ServiceComponent findByBNS_BNU(String buildNamespace,
805 long buildNumber)
806 throws NoSuchServiceComponentException, SystemException {
807 ServiceComponent serviceComponent = fetchByBNS_BNU(buildNamespace,
808 buildNumber);
809
810 if (serviceComponent == null) {
811 StringBundler msg = new StringBundler(6);
812
813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
814
815 msg.append("buildNamespace=");
816 msg.append(buildNamespace);
817
818 msg.append(", buildNumber=");
819 msg.append(buildNumber);
820
821 msg.append(StringPool.CLOSE_CURLY_BRACE);
822
823 if (_log.isWarnEnabled()) {
824 _log.warn(msg.toString());
825 }
826
827 throw new NoSuchServiceComponentException(msg.toString());
828 }
829
830 return serviceComponent;
831 }
832
833
841 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
842 long buildNumber) throws SystemException {
843 return fetchByBNS_BNU(buildNamespace, buildNumber, true);
844 }
845
846
854 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
855 long buildNumber, boolean retrieveFromCache) throws SystemException {
856 Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
857
858 Object result = null;
859
860 if (retrieveFromCache) {
861 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_BNS_BNU,
862 finderArgs, this);
863 }
864
865 if (result == null) {
866 Session session = null;
867
868 try {
869 session = openSession();
870
871 StringBundler query = new StringBundler(4);
872
873 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
874
875 if (buildNamespace == null) {
876 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
877 }
878 else {
879 if (buildNamespace.equals(StringPool.BLANK)) {
880 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
881 }
882 else {
883 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
884 }
885 }
886
887 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
888
889 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
890
891 String sql = query.toString();
892
893 Query q = session.createQuery(sql);
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 if (buildNamespace != null) {
898 qPos.add(buildNamespace);
899 }
900
901 qPos.add(buildNumber);
902
903 List<ServiceComponent> list = q.list();
904
905 result = list;
906
907 ServiceComponent serviceComponent = null;
908
909 if (list.isEmpty()) {
910 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
911 finderArgs, list);
912 }
913 else {
914 serviceComponent = list.get(0);
915
916 cacheResult(serviceComponent);
917
918 if ((serviceComponent.getBuildNamespace() == null) ||
919 !serviceComponent.getBuildNamespace()
920 .equals(buildNamespace) ||
921 (serviceComponent.getBuildNumber() != buildNumber)) {
922 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
923 finderArgs, serviceComponent);
924 }
925 }
926
927 return serviceComponent;
928 }
929 catch (Exception e) {
930 throw processException(e);
931 }
932 finally {
933 if (result == null) {
934 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
935 finderArgs, new ArrayList<ServiceComponent>());
936 }
937
938 closeSession(session);
939 }
940 }
941 else {
942 if (result instanceof List<?>) {
943 return null;
944 }
945 else {
946 return (ServiceComponent)result;
947 }
948 }
949 }
950
951
957 public List<ServiceComponent> findAll() throws SystemException {
958 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
959 }
960
961
973 public List<ServiceComponent> findAll(int start, int end)
974 throws SystemException {
975 return findAll(start, end, null);
976 }
977
978
991 public List<ServiceComponent> findAll(int start, int end,
992 OrderByComparator orderByComparator) throws SystemException {
993 Object[] finderArgs = new Object[] {
994 String.valueOf(start), String.valueOf(end),
995 String.valueOf(orderByComparator)
996 };
997
998 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
999 finderArgs, this);
1000
1001 if (list == null) {
1002 Session session = null;
1003
1004 try {
1005 session = openSession();
1006
1007 StringBundler query = null;
1008 String sql = null;
1009
1010 if (orderByComparator != null) {
1011 query = new StringBundler(2 +
1012 (orderByComparator.getOrderByFields().length * 3));
1013
1014 query.append(_SQL_SELECT_SERVICECOMPONENT);
1015
1016 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1017 orderByComparator);
1018
1019 sql = query.toString();
1020 }
1021 else {
1022 sql = _SQL_SELECT_SERVICECOMPONENT.concat(ServiceComponentModelImpl.ORDER_BY_JPQL);
1023 }
1024
1025 Query q = session.createQuery(sql);
1026
1027 if (orderByComparator == null) {
1028 list = (List<ServiceComponent>)QueryUtil.list(q,
1029 getDialect(), start, end, false);
1030
1031 Collections.sort(list);
1032 }
1033 else {
1034 list = (List<ServiceComponent>)QueryUtil.list(q,
1035 getDialect(), start, end);
1036 }
1037 }
1038 catch (Exception e) {
1039 throw processException(e);
1040 }
1041 finally {
1042 if (list == null) {
1043 list = new ArrayList<ServiceComponent>();
1044 }
1045
1046 cacheResult(list);
1047
1048 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1049
1050 closeSession(session);
1051 }
1052 }
1053
1054 return list;
1055 }
1056
1057
1063 public void removeByBuildNamespace(String buildNamespace)
1064 throws SystemException {
1065 for (ServiceComponent serviceComponent : findByBuildNamespace(
1066 buildNamespace)) {
1067 remove(serviceComponent);
1068 }
1069 }
1070
1071
1078 public void removeByBNS_BNU(String buildNamespace, long buildNumber)
1079 throws NoSuchServiceComponentException, SystemException {
1080 ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
1081 buildNumber);
1082
1083 remove(serviceComponent);
1084 }
1085
1086
1091 public void removeAll() throws SystemException {
1092 for (ServiceComponent serviceComponent : findAll()) {
1093 remove(serviceComponent);
1094 }
1095 }
1096
1097
1104 public int countByBuildNamespace(String buildNamespace)
1105 throws SystemException {
1106 Object[] finderArgs = new Object[] { buildNamespace };
1107
1108 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1109 finderArgs, this);
1110
1111 if (count == null) {
1112 Session session = null;
1113
1114 try {
1115 session = openSession();
1116
1117 StringBundler query = new StringBundler(2);
1118
1119 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
1120
1121 if (buildNamespace == null) {
1122 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
1123 }
1124 else {
1125 if (buildNamespace.equals(StringPool.BLANK)) {
1126 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
1127 }
1128 else {
1129 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
1130 }
1131 }
1132
1133 String sql = query.toString();
1134
1135 Query q = session.createQuery(sql);
1136
1137 QueryPos qPos = QueryPos.getInstance(q);
1138
1139 if (buildNamespace != null) {
1140 qPos.add(buildNamespace);
1141 }
1142
1143 count = (Long)q.uniqueResult();
1144 }
1145 catch (Exception e) {
1146 throw processException(e);
1147 }
1148 finally {
1149 if (count == null) {
1150 count = Long.valueOf(0);
1151 }
1152
1153 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1154 finderArgs, count);
1155
1156 closeSession(session);
1157 }
1158 }
1159
1160 return count.intValue();
1161 }
1162
1163
1171 public int countByBNS_BNU(String buildNamespace, long buildNumber)
1172 throws SystemException {
1173 Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
1174
1175 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BNS_BNU,
1176 finderArgs, this);
1177
1178 if (count == null) {
1179 Session session = null;
1180
1181 try {
1182 session = openSession();
1183
1184 StringBundler query = new StringBundler(3);
1185
1186 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
1187
1188 if (buildNamespace == null) {
1189 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
1190 }
1191 else {
1192 if (buildNamespace.equals(StringPool.BLANK)) {
1193 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
1194 }
1195 else {
1196 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
1197 }
1198 }
1199
1200 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
1201
1202 String sql = query.toString();
1203
1204 Query q = session.createQuery(sql);
1205
1206 QueryPos qPos = QueryPos.getInstance(q);
1207
1208 if (buildNamespace != null) {
1209 qPos.add(buildNamespace);
1210 }
1211
1212 qPos.add(buildNumber);
1213
1214 count = (Long)q.uniqueResult();
1215 }
1216 catch (Exception e) {
1217 throw processException(e);
1218 }
1219 finally {
1220 if (count == null) {
1221 count = Long.valueOf(0);
1222 }
1223
1224 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU,
1225 finderArgs, count);
1226
1227 closeSession(session);
1228 }
1229 }
1230
1231 return count.intValue();
1232 }
1233
1234
1240 public int countAll() throws SystemException {
1241 Object[] finderArgs = new Object[0];
1242
1243 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1244 finderArgs, this);
1245
1246 if (count == null) {
1247 Session session = null;
1248
1249 try {
1250 session = openSession();
1251
1252 Query q = session.createQuery(_SQL_COUNT_SERVICECOMPONENT);
1253
1254 count = (Long)q.uniqueResult();
1255 }
1256 catch (Exception e) {
1257 throw processException(e);
1258 }
1259 finally {
1260 if (count == null) {
1261 count = Long.valueOf(0);
1262 }
1263
1264 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1265 count);
1266
1267 closeSession(session);
1268 }
1269 }
1270
1271 return count.intValue();
1272 }
1273
1274
1277 public void afterPropertiesSet() {
1278 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1279 com.liferay.portal.util.PropsUtil.get(
1280 "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1281
1282 if (listenerClassNames.length > 0) {
1283 try {
1284 List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1285
1286 for (String listenerClassName : listenerClassNames) {
1287 listenersList.add((ModelListener<ServiceComponent>)InstanceFactory.newInstance(
1288 listenerClassName));
1289 }
1290
1291 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1292 }
1293 catch (Exception e) {
1294 _log.error(e);
1295 }
1296 }
1297 }
1298
1299 public void destroy() {
1300 EntityCacheUtil.removeCache(ServiceComponentImpl.class.getName());
1301 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1302 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1303 }
1304
1305 @BeanReference(type = AccountPersistence.class)
1306 protected AccountPersistence accountPersistence;
1307 @BeanReference(type = AddressPersistence.class)
1308 protected AddressPersistence addressPersistence;
1309 @BeanReference(type = BrowserTrackerPersistence.class)
1310 protected BrowserTrackerPersistence browserTrackerPersistence;
1311 @BeanReference(type = ClassNamePersistence.class)
1312 protected ClassNamePersistence classNamePersistence;
1313 @BeanReference(type = ClusterGroupPersistence.class)
1314 protected ClusterGroupPersistence clusterGroupPersistence;
1315 @BeanReference(type = CompanyPersistence.class)
1316 protected CompanyPersistence companyPersistence;
1317 @BeanReference(type = ContactPersistence.class)
1318 protected ContactPersistence contactPersistence;
1319 @BeanReference(type = CountryPersistence.class)
1320 protected CountryPersistence countryPersistence;
1321 @BeanReference(type = EmailAddressPersistence.class)
1322 protected EmailAddressPersistence emailAddressPersistence;
1323 @BeanReference(type = GroupPersistence.class)
1324 protected GroupPersistence groupPersistence;
1325 @BeanReference(type = ImagePersistence.class)
1326 protected ImagePersistence imagePersistence;
1327 @BeanReference(type = LayoutPersistence.class)
1328 protected LayoutPersistence layoutPersistence;
1329 @BeanReference(type = LayoutPrototypePersistence.class)
1330 protected LayoutPrototypePersistence layoutPrototypePersistence;
1331 @BeanReference(type = LayoutSetPersistence.class)
1332 protected LayoutSetPersistence layoutSetPersistence;
1333 @BeanReference(type = LayoutSetPrototypePersistence.class)
1334 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1335 @BeanReference(type = ListTypePersistence.class)
1336 protected ListTypePersistence listTypePersistence;
1337 @BeanReference(type = LockPersistence.class)
1338 protected LockPersistence lockPersistence;
1339 @BeanReference(type = MembershipRequestPersistence.class)
1340 protected MembershipRequestPersistence membershipRequestPersistence;
1341 @BeanReference(type = OrganizationPersistence.class)
1342 protected OrganizationPersistence organizationPersistence;
1343 @BeanReference(type = OrgGroupPermissionPersistence.class)
1344 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1345 @BeanReference(type = OrgGroupRolePersistence.class)
1346 protected OrgGroupRolePersistence orgGroupRolePersistence;
1347 @BeanReference(type = OrgLaborPersistence.class)
1348 protected OrgLaborPersistence orgLaborPersistence;
1349 @BeanReference(type = PasswordPolicyPersistence.class)
1350 protected PasswordPolicyPersistence passwordPolicyPersistence;
1351 @BeanReference(type = PasswordPolicyRelPersistence.class)
1352 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1353 @BeanReference(type = PasswordTrackerPersistence.class)
1354 protected PasswordTrackerPersistence passwordTrackerPersistence;
1355 @BeanReference(type = PermissionPersistence.class)
1356 protected PermissionPersistence permissionPersistence;
1357 @BeanReference(type = PhonePersistence.class)
1358 protected PhonePersistence phonePersistence;
1359 @BeanReference(type = PluginSettingPersistence.class)
1360 protected PluginSettingPersistence pluginSettingPersistence;
1361 @BeanReference(type = PortletPersistence.class)
1362 protected PortletPersistence portletPersistence;
1363 @BeanReference(type = PortletItemPersistence.class)
1364 protected PortletItemPersistence portletItemPersistence;
1365 @BeanReference(type = PortletPreferencesPersistence.class)
1366 protected PortletPreferencesPersistence portletPreferencesPersistence;
1367 @BeanReference(type = RegionPersistence.class)
1368 protected RegionPersistence regionPersistence;
1369 @BeanReference(type = ReleasePersistence.class)
1370 protected ReleasePersistence releasePersistence;
1371 @BeanReference(type = ResourcePersistence.class)
1372 protected ResourcePersistence resourcePersistence;
1373 @BeanReference(type = ResourceActionPersistence.class)
1374 protected ResourceActionPersistence resourceActionPersistence;
1375 @BeanReference(type = ResourceCodePersistence.class)
1376 protected ResourceCodePersistence resourceCodePersistence;
1377 @BeanReference(type = ResourcePermissionPersistence.class)
1378 protected ResourcePermissionPersistence resourcePermissionPersistence;
1379 @BeanReference(type = RolePersistence.class)
1380 protected RolePersistence rolePersistence;
1381 @BeanReference(type = ServiceComponentPersistence.class)
1382 protected ServiceComponentPersistence serviceComponentPersistence;
1383 @BeanReference(type = ShardPersistence.class)
1384 protected ShardPersistence shardPersistence;
1385 @BeanReference(type = SubscriptionPersistence.class)
1386 protected SubscriptionPersistence subscriptionPersistence;
1387 @BeanReference(type = TicketPersistence.class)
1388 protected TicketPersistence ticketPersistence;
1389 @BeanReference(type = TeamPersistence.class)
1390 protected TeamPersistence teamPersistence;
1391 @BeanReference(type = UserPersistence.class)
1392 protected UserPersistence userPersistence;
1393 @BeanReference(type = UserGroupPersistence.class)
1394 protected UserGroupPersistence userGroupPersistence;
1395 @BeanReference(type = UserGroupGroupRolePersistence.class)
1396 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1397 @BeanReference(type = UserGroupRolePersistence.class)
1398 protected UserGroupRolePersistence userGroupRolePersistence;
1399 @BeanReference(type = UserIdMapperPersistence.class)
1400 protected UserIdMapperPersistence userIdMapperPersistence;
1401 @BeanReference(type = UserTrackerPersistence.class)
1402 protected UserTrackerPersistence userTrackerPersistence;
1403 @BeanReference(type = UserTrackerPathPersistence.class)
1404 protected UserTrackerPathPersistence userTrackerPathPersistence;
1405 @BeanReference(type = WebDAVPropsPersistence.class)
1406 protected WebDAVPropsPersistence webDAVPropsPersistence;
1407 @BeanReference(type = WebsitePersistence.class)
1408 protected WebsitePersistence websitePersistence;
1409 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1410 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1411 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1412 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1413 private static final String _SQL_SELECT_SERVICECOMPONENT = "SELECT serviceComponent FROM ServiceComponent serviceComponent";
1414 private static final String _SQL_SELECT_SERVICECOMPONENT_WHERE = "SELECT serviceComponent FROM ServiceComponent serviceComponent WHERE ";
1415 private static final String _SQL_COUNT_SERVICECOMPONENT = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent";
1416 private static final String _SQL_COUNT_SERVICECOMPONENT_WHERE = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent WHERE ";
1417 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL";
1418 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ?";
1419 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?)";
1420 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL AND ";
1421 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ? AND ";
1422 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?) AND ";
1423 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2 = "serviceComponent.buildNumber = ?";
1424 private static final String _ORDER_BY_ENTITY_ALIAS = "serviceComponent.";
1425 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ServiceComponent exists with the primary key ";
1426 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ServiceComponent exists with the key {";
1427 private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1428 }