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.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.ServiceComponent;
041 import com.liferay.portal.model.impl.ServiceComponentImpl;
042 import com.liferay.portal.model.impl.ServiceComponentModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ServiceComponentPersistenceImpl extends BasePersistenceImpl<ServiceComponent>
064 implements ServiceComponentPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ServiceComponentImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
076 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
077 ServiceComponentImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078 "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
080 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
081 ServiceComponentImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
084 ServiceComponentModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_BUILDNAMESPACE =
087 new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
088 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
089 ServiceComponentImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090 "findByBuildNamespace",
091 new String[] {
092 String.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE =
098 new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
099 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
100 ServiceComponentImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByBuildNamespace",
102 new String[] { String.class.getName() },
103 ServiceComponentModelImpl.BUILDNAMESPACE_COLUMN_BITMASK |
104 ServiceComponentModelImpl.BUILDNUMBER_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
106 ServiceComponentModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByBuildNamespace",
108 new String[] { String.class.getName() });
109
110
117 public List<ServiceComponent> findByBuildNamespace(String buildNamespace)
118 throws SystemException {
119 return findByBuildNamespace(buildNamespace, QueryUtil.ALL_POS,
120 QueryUtil.ALL_POS, null);
121 }
122
123
136 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
137 int start, int end) throws SystemException {
138 return findByBuildNamespace(buildNamespace, start, end, null);
139 }
140
141
155 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
156 int start, int end, OrderByComparator orderByComparator)
157 throws SystemException {
158 boolean pagination = true;
159 FinderPath finderPath = null;
160 Object[] finderArgs = null;
161
162 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163 (orderByComparator == null)) {
164 pagination = false;
165 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE;
166 finderArgs = new Object[] { buildNamespace };
167 }
168 else {
169 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BUILDNAMESPACE;
170 finderArgs = new Object[] {
171 buildNamespace,
172
173 start, end, orderByComparator
174 };
175 }
176
177 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(finderPath,
178 finderArgs, this);
179
180 if ((list != null) && !list.isEmpty()) {
181 for (ServiceComponent serviceComponent : list) {
182 if (!Validator.equals(buildNamespace,
183 serviceComponent.getBuildNamespace())) {
184 list = null;
185
186 break;
187 }
188 }
189 }
190
191 if (list == null) {
192 StringBundler query = null;
193
194 if (orderByComparator != null) {
195 query = new StringBundler(3 +
196 (orderByComparator.getOrderByFields().length * 3));
197 }
198 else {
199 query = new StringBundler(3);
200 }
201
202 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
203
204 if (buildNamespace == null) {
205 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
206 }
207 else {
208 if (buildNamespace.equals(StringPool.BLANK)) {
209 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
210 }
211 else {
212 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
213 }
214 }
215
216 if (orderByComparator != null) {
217 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218 orderByComparator);
219 }
220 else
221 if (pagination) {
222 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
223 }
224
225 String sql = query.toString();
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 Query q = session.createQuery(sql);
233
234 QueryPos qPos = QueryPos.getInstance(q);
235
236 if (buildNamespace != null) {
237 qPos.add(buildNamespace);
238 }
239
240 if (!pagination) {
241 list = (List<ServiceComponent>)QueryUtil.list(q,
242 getDialect(), start, end, false);
243
244 Collections.sort(list);
245
246 list = new UnmodifiableList<ServiceComponent>(list);
247 }
248 else {
249 list = (List<ServiceComponent>)QueryUtil.list(q,
250 getDialect(), start, end);
251 }
252
253 cacheResult(list);
254
255 FinderCacheUtil.putResult(finderPath, finderArgs, list);
256 }
257 catch (Exception e) {
258 FinderCacheUtil.removeResult(finderPath, finderArgs);
259
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265 }
266
267 return list;
268 }
269
270
279 public ServiceComponent findByBuildNamespace_First(String buildNamespace,
280 OrderByComparator orderByComparator)
281 throws NoSuchServiceComponentException, SystemException {
282 ServiceComponent serviceComponent = fetchByBuildNamespace_First(buildNamespace,
283 orderByComparator);
284
285 if (serviceComponent != null) {
286 return serviceComponent;
287 }
288
289 StringBundler msg = new StringBundler(4);
290
291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292
293 msg.append("buildNamespace=");
294 msg.append(buildNamespace);
295
296 msg.append(StringPool.CLOSE_CURLY_BRACE);
297
298 throw new NoSuchServiceComponentException(msg.toString());
299 }
300
301
309 public ServiceComponent fetchByBuildNamespace_First(String buildNamespace,
310 OrderByComparator orderByComparator) throws SystemException {
311 List<ServiceComponent> list = findByBuildNamespace(buildNamespace, 0,
312 1, orderByComparator);
313
314 if (!list.isEmpty()) {
315 return list.get(0);
316 }
317
318 return null;
319 }
320
321
330 public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
331 OrderByComparator orderByComparator)
332 throws NoSuchServiceComponentException, SystemException {
333 ServiceComponent serviceComponent = fetchByBuildNamespace_Last(buildNamespace,
334 orderByComparator);
335
336 if (serviceComponent != null) {
337 return serviceComponent;
338 }
339
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("buildNamespace=");
345 msg.append(buildNamespace);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchServiceComponentException(msg.toString());
350 }
351
352
360 public ServiceComponent fetchByBuildNamespace_Last(String buildNamespace,
361 OrderByComparator orderByComparator) throws SystemException {
362 int count = countByBuildNamespace(buildNamespace);
363
364 List<ServiceComponent> list = findByBuildNamespace(buildNamespace,
365 count - 1, count, orderByComparator);
366
367 if (!list.isEmpty()) {
368 return list.get(0);
369 }
370
371 return null;
372 }
373
374
384 public ServiceComponent[] findByBuildNamespace_PrevAndNext(
385 long serviceComponentId, String buildNamespace,
386 OrderByComparator orderByComparator)
387 throws NoSuchServiceComponentException, SystemException {
388 ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
389
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 ServiceComponent[] array = new ServiceComponentImpl[3];
396
397 array[0] = getByBuildNamespace_PrevAndNext(session,
398 serviceComponent, buildNamespace, orderByComparator, true);
399
400 array[1] = serviceComponent;
401
402 array[2] = getByBuildNamespace_PrevAndNext(session,
403 serviceComponent, buildNamespace, orderByComparator, false);
404
405 return array;
406 }
407 catch (Exception e) {
408 throw processException(e);
409 }
410 finally {
411 closeSession(session);
412 }
413 }
414
415 protected ServiceComponent getByBuildNamespace_PrevAndNext(
416 Session session, ServiceComponent serviceComponent,
417 String buildNamespace, OrderByComparator orderByComparator,
418 boolean previous) {
419 StringBundler query = null;
420
421 if (orderByComparator != null) {
422 query = new StringBundler(6 +
423 (orderByComparator.getOrderByFields().length * 6));
424 }
425 else {
426 query = new StringBundler(3);
427 }
428
429 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
430
431 if (buildNamespace == null) {
432 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
433 }
434 else {
435 if (buildNamespace.equals(StringPool.BLANK)) {
436 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
437 }
438 else {
439 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
440 }
441 }
442
443 if (orderByComparator != null) {
444 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445
446 if (orderByConditionFields.length > 0) {
447 query.append(WHERE_AND);
448 }
449
450 for (int i = 0; i < orderByConditionFields.length; i++) {
451 query.append(_ORDER_BY_ENTITY_ALIAS);
452 query.append(orderByConditionFields[i]);
453
454 if ((i + 1) < orderByConditionFields.length) {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(WHERE_GREATER_THAN_HAS_NEXT);
457 }
458 else {
459 query.append(WHERE_LESSER_THAN_HAS_NEXT);
460 }
461 }
462 else {
463 if (orderByComparator.isAscending() ^ previous) {
464 query.append(WHERE_GREATER_THAN);
465 }
466 else {
467 query.append(WHERE_LESSER_THAN);
468 }
469 }
470 }
471
472 query.append(ORDER_BY_CLAUSE);
473
474 String[] orderByFields = orderByComparator.getOrderByFields();
475
476 for (int i = 0; i < orderByFields.length; i++) {
477 query.append(_ORDER_BY_ENTITY_ALIAS);
478 query.append(orderByFields[i]);
479
480 if ((i + 1) < orderByFields.length) {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(ORDER_BY_ASC_HAS_NEXT);
483 }
484 else {
485 query.append(ORDER_BY_DESC_HAS_NEXT);
486 }
487 }
488 else {
489 if (orderByComparator.isAscending() ^ previous) {
490 query.append(ORDER_BY_ASC);
491 }
492 else {
493 query.append(ORDER_BY_DESC);
494 }
495 }
496 }
497 }
498 else {
499 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
500 }
501
502 String sql = query.toString();
503
504 Query q = session.createQuery(sql);
505
506 q.setFirstResult(0);
507 q.setMaxResults(2);
508
509 QueryPos qPos = QueryPos.getInstance(q);
510
511 if (buildNamespace != null) {
512 qPos.add(buildNamespace);
513 }
514
515 if (orderByComparator != null) {
516 Object[] values = orderByComparator.getOrderByConditionValues(serviceComponent);
517
518 for (Object value : values) {
519 qPos.add(value);
520 }
521 }
522
523 List<ServiceComponent> list = q.list();
524
525 if (list.size() == 2) {
526 return list.get(1);
527 }
528 else {
529 return null;
530 }
531 }
532
533
539 public void removeByBuildNamespace(String buildNamespace)
540 throws SystemException {
541 for (ServiceComponent serviceComponent : findByBuildNamespace(
542 buildNamespace, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
543 remove(serviceComponent);
544 }
545 }
546
547
554 public int countByBuildNamespace(String buildNamespace)
555 throws SystemException {
556 FinderPath finderPath = FINDER_PATH_COUNT_BY_BUILDNAMESPACE;
557
558 Object[] finderArgs = new Object[] { buildNamespace };
559
560 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
561 this);
562
563 if (count == null) {
564 StringBundler query = new StringBundler(2);
565
566 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
567
568 if (buildNamespace == null) {
569 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
570 }
571 else {
572 if (buildNamespace.equals(StringPool.BLANK)) {
573 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
574 }
575 else {
576 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
577 }
578 }
579
580 String sql = query.toString();
581
582 Session session = null;
583
584 try {
585 session = openSession();
586
587 Query q = session.createQuery(sql);
588
589 QueryPos qPos = QueryPos.getInstance(q);
590
591 if (buildNamespace != null) {
592 qPos.add(buildNamespace);
593 }
594
595 count = (Long)q.uniqueResult();
596
597 FinderCacheUtil.putResult(finderPath, finderArgs, count);
598 }
599 catch (Exception e) {
600 FinderCacheUtil.removeResult(finderPath, finderArgs);
601
602 throw processException(e);
603 }
604 finally {
605 closeSession(session);
606 }
607 }
608
609 return count.intValue();
610 }
611
612 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL";
613 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ?";
614 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?)";
615 public static final FinderPath FINDER_PATH_FETCH_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
616 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
617 ServiceComponentImpl.class, FINDER_CLASS_NAME_ENTITY,
618 "fetchByBNS_BNU",
619 new String[] { String.class.getName(), Long.class.getName() },
620 ServiceComponentModelImpl.BUILDNAMESPACE_COLUMN_BITMASK |
621 ServiceComponentModelImpl.BUILDNUMBER_COLUMN_BITMASK);
622 public static final FinderPath FINDER_PATH_COUNT_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
623 ServiceComponentModelImpl.FINDER_CACHE_ENABLED, Long.class,
624 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByBNS_BNU",
625 new String[] { String.class.getName(), Long.class.getName() });
626
627
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 StringBundler msg = new StringBundler(6);
644
645 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646
647 msg.append("buildNamespace=");
648 msg.append(buildNamespace);
649
650 msg.append(", buildNumber=");
651 msg.append(buildNumber);
652
653 msg.append(StringPool.CLOSE_CURLY_BRACE);
654
655 if (_log.isWarnEnabled()) {
656 _log.warn(msg.toString());
657 }
658
659 throw new NoSuchServiceComponentException(msg.toString());
660 }
661
662 return serviceComponent;
663 }
664
665
673 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
674 long buildNumber) throws SystemException {
675 return fetchByBNS_BNU(buildNamespace, buildNumber, true);
676 }
677
678
687 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
688 long buildNumber, boolean retrieveFromCache) throws SystemException {
689 Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
690
691 Object result = null;
692
693 if (retrieveFromCache) {
694 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_BNS_BNU,
695 finderArgs, this);
696 }
697
698 if (result instanceof ServiceComponent) {
699 ServiceComponent serviceComponent = (ServiceComponent)result;
700
701 if (!Validator.equals(buildNamespace,
702 serviceComponent.getBuildNamespace()) ||
703 (buildNumber != serviceComponent.getBuildNumber())) {
704 result = null;
705 }
706 }
707
708 if (result == null) {
709 StringBundler query = new StringBundler(4);
710
711 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
712
713 if (buildNamespace == null) {
714 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
715 }
716 else {
717 if (buildNamespace.equals(StringPool.BLANK)) {
718 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
719 }
720 else {
721 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
722 }
723 }
724
725 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
726
727 String sql = query.toString();
728
729 Session session = null;
730
731 try {
732 session = openSession();
733
734 Query q = session.createQuery(sql);
735
736 QueryPos qPos = QueryPos.getInstance(q);
737
738 if (buildNamespace != null) {
739 qPos.add(buildNamespace);
740 }
741
742 qPos.add(buildNumber);
743
744 List<ServiceComponent> list = q.list();
745
746 if (list.isEmpty()) {
747 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
748 finderArgs, list);
749 }
750 else {
751 ServiceComponent serviceComponent = list.get(0);
752
753 result = serviceComponent;
754
755 cacheResult(serviceComponent);
756
757 if ((serviceComponent.getBuildNamespace() == null) ||
758 !serviceComponent.getBuildNamespace()
759 .equals(buildNamespace) ||
760 (serviceComponent.getBuildNumber() != buildNumber)) {
761 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
762 finderArgs, serviceComponent);
763 }
764 }
765 }
766 catch (Exception e) {
767 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
768 finderArgs);
769
770 throw processException(e);
771 }
772 finally {
773 closeSession(session);
774 }
775 }
776
777 if (result instanceof List<?>) {
778 return null;
779 }
780 else {
781 return (ServiceComponent)result;
782 }
783 }
784
785
793 public ServiceComponent removeByBNS_BNU(String buildNamespace,
794 long buildNumber)
795 throws NoSuchServiceComponentException, SystemException {
796 ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
797 buildNumber);
798
799 return remove(serviceComponent);
800 }
801
802
810 public int countByBNS_BNU(String buildNamespace, long buildNumber)
811 throws SystemException {
812 FinderPath finderPath = FINDER_PATH_COUNT_BY_BNS_BNU;
813
814 Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
815
816 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
817 this);
818
819 if (count == null) {
820 StringBundler query = new StringBundler(3);
821
822 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
823
824 if (buildNamespace == null) {
825 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
826 }
827 else {
828 if (buildNamespace.equals(StringPool.BLANK)) {
829 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
830 }
831 else {
832 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
833 }
834 }
835
836 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
837
838 String sql = query.toString();
839
840 Session session = null;
841
842 try {
843 session = openSession();
844
845 Query q = session.createQuery(sql);
846
847 QueryPos qPos = QueryPos.getInstance(q);
848
849 if (buildNamespace != null) {
850 qPos.add(buildNamespace);
851 }
852
853 qPos.add(buildNumber);
854
855 count = (Long)q.uniqueResult();
856
857 FinderCacheUtil.putResult(finderPath, finderArgs, count);
858 }
859 catch (Exception e) {
860 FinderCacheUtil.removeResult(finderPath, finderArgs);
861
862 throw processException(e);
863 }
864 finally {
865 closeSession(session);
866 }
867 }
868
869 return count.intValue();
870 }
871
872 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL AND ";
873 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ? AND ";
874 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?) AND ";
875 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2 = "serviceComponent.buildNumber = ?";
876
877
882 public void cacheResult(ServiceComponent serviceComponent) {
883 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
884 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
885 serviceComponent);
886
887 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
888 new Object[] {
889 serviceComponent.getBuildNamespace(),
890 Long.valueOf(serviceComponent.getBuildNumber())
891 }, serviceComponent);
892
893 serviceComponent.resetOriginalValues();
894 }
895
896
901 public void cacheResult(List<ServiceComponent> serviceComponents) {
902 for (ServiceComponent serviceComponent : serviceComponents) {
903 if (EntityCacheUtil.getResult(
904 ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
905 ServiceComponentImpl.class,
906 serviceComponent.getPrimaryKey()) == null) {
907 cacheResult(serviceComponent);
908 }
909 else {
910 serviceComponent.resetOriginalValues();
911 }
912 }
913 }
914
915
922 @Override
923 public void clearCache() {
924 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
925 CacheRegistryUtil.clear(ServiceComponentImpl.class.getName());
926 }
927
928 EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
929
930 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
931 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
932 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
933 }
934
935
942 @Override
943 public void clearCache(ServiceComponent serviceComponent) {
944 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
945 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
946
947 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
948 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
949
950 clearUniqueFindersCache(serviceComponent);
951 }
952
953 @Override
954 public void clearCache(List<ServiceComponent> serviceComponents) {
955 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
956 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
957
958 for (ServiceComponent serviceComponent : serviceComponents) {
959 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
960 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
961
962 clearUniqueFindersCache(serviceComponent);
963 }
964 }
965
966 protected void cacheUniqueFindersCache(ServiceComponent serviceComponent) {
967 if (serviceComponent.isNew()) {
968 Object[] args = new Object[] {
969 serviceComponent.getBuildNamespace(),
970 Long.valueOf(serviceComponent.getBuildNumber())
971 };
972
973 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU, args,
974 Long.valueOf(1));
975 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU, args,
976 serviceComponent);
977 }
978 else {
979 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
980
981 if ((serviceComponentModelImpl.getColumnBitmask() &
982 FINDER_PATH_FETCH_BY_BNS_BNU.getColumnBitmask()) != 0) {
983 Object[] args = new Object[] {
984 serviceComponent.getBuildNamespace(),
985 Long.valueOf(serviceComponent.getBuildNumber())
986 };
987
988 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU, args,
989 Long.valueOf(1));
990 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU, args,
991 serviceComponent);
992 }
993 }
994 }
995
996 protected void clearUniqueFindersCache(ServiceComponent serviceComponent) {
997 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
998
999 Object[] args = new Object[] {
1000 serviceComponent.getBuildNamespace(),
1001 Long.valueOf(serviceComponent.getBuildNumber())
1002 };
1003
1004 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BNS_BNU, args);
1005 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU, args);
1006
1007 if ((serviceComponentModelImpl.getColumnBitmask() &
1008 FINDER_PATH_FETCH_BY_BNS_BNU.getColumnBitmask()) != 0) {
1009 args = new Object[] {
1010 serviceComponentModelImpl.getOriginalBuildNamespace(),
1011 Long.valueOf(serviceComponentModelImpl.getOriginalBuildNumber())
1012 };
1013
1014 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BNS_BNU, args);
1015 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU, args);
1016 }
1017 }
1018
1019
1025 public ServiceComponent create(long serviceComponentId) {
1026 ServiceComponent serviceComponent = new ServiceComponentImpl();
1027
1028 serviceComponent.setNew(true);
1029 serviceComponent.setPrimaryKey(serviceComponentId);
1030
1031 return serviceComponent;
1032 }
1033
1034
1042 public ServiceComponent remove(long serviceComponentId)
1043 throws NoSuchServiceComponentException, SystemException {
1044 return remove(Long.valueOf(serviceComponentId));
1045 }
1046
1047
1055 @Override
1056 public ServiceComponent remove(Serializable primaryKey)
1057 throws NoSuchServiceComponentException, SystemException {
1058 Session session = null;
1059
1060 try {
1061 session = openSession();
1062
1063 ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1064 primaryKey);
1065
1066 if (serviceComponent == null) {
1067 if (_log.isWarnEnabled()) {
1068 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1069 }
1070
1071 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1072 primaryKey);
1073 }
1074
1075 return remove(serviceComponent);
1076 }
1077 catch (NoSuchServiceComponentException nsee) {
1078 throw nsee;
1079 }
1080 catch (Exception e) {
1081 throw processException(e);
1082 }
1083 finally {
1084 closeSession(session);
1085 }
1086 }
1087
1088 @Override
1089 protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
1090 throws SystemException {
1091 serviceComponent = toUnwrappedModel(serviceComponent);
1092
1093 Session session = null;
1094
1095 try {
1096 session = openSession();
1097
1098 if (!session.contains(serviceComponent)) {
1099 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1100 serviceComponent.getPrimaryKeyObj());
1101 }
1102
1103 if (serviceComponent != null) {
1104 session.delete(serviceComponent);
1105 }
1106 }
1107 catch (Exception e) {
1108 throw processException(e);
1109 }
1110 finally {
1111 closeSession(session);
1112 }
1113
1114 if (serviceComponent != null) {
1115 clearCache(serviceComponent);
1116 }
1117
1118 return serviceComponent;
1119 }
1120
1121 @Override
1122 public ServiceComponent updateImpl(
1123 com.liferay.portal.model.ServiceComponent serviceComponent)
1124 throws SystemException {
1125 serviceComponent = toUnwrappedModel(serviceComponent);
1126
1127 boolean isNew = serviceComponent.isNew();
1128
1129 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1130
1131 Session session = null;
1132
1133 try {
1134 session = openSession();
1135
1136 if (serviceComponent.isNew()) {
1137 session.save(serviceComponent);
1138
1139 serviceComponent.setNew(false);
1140 }
1141 else {
1142 session.merge(serviceComponent);
1143 }
1144 }
1145 catch (Exception e) {
1146 throw processException(e);
1147 }
1148 finally {
1149 closeSession(session);
1150 }
1151
1152 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1153
1154 if (isNew || !ServiceComponentModelImpl.COLUMN_BITMASK_ENABLED) {
1155 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1156 }
1157
1158 else {
1159 if ((serviceComponentModelImpl.getColumnBitmask() &
1160 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE.getColumnBitmask()) != 0) {
1161 Object[] args = new Object[] {
1162 serviceComponentModelImpl.getOriginalBuildNamespace()
1163 };
1164
1165 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1166 args);
1167 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE,
1168 args);
1169
1170 args = new Object[] {
1171 serviceComponentModelImpl.getBuildNamespace()
1172 };
1173
1174 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1175 args);
1176 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE,
1177 args);
1178 }
1179 }
1180
1181 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1182 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
1183 serviceComponent);
1184
1185 clearUniqueFindersCache(serviceComponent);
1186 cacheUniqueFindersCache(serviceComponent);
1187
1188 return serviceComponent;
1189 }
1190
1191 protected ServiceComponent toUnwrappedModel(
1192 ServiceComponent serviceComponent) {
1193 if (serviceComponent instanceof ServiceComponentImpl) {
1194 return serviceComponent;
1195 }
1196
1197 ServiceComponentImpl serviceComponentImpl = new ServiceComponentImpl();
1198
1199 serviceComponentImpl.setNew(serviceComponent.isNew());
1200 serviceComponentImpl.setPrimaryKey(serviceComponent.getPrimaryKey());
1201
1202 serviceComponentImpl.setServiceComponentId(serviceComponent.getServiceComponentId());
1203 serviceComponentImpl.setBuildNamespace(serviceComponent.getBuildNamespace());
1204 serviceComponentImpl.setBuildNumber(serviceComponent.getBuildNumber());
1205 serviceComponentImpl.setBuildDate(serviceComponent.getBuildDate());
1206 serviceComponentImpl.setData(serviceComponent.getData());
1207
1208 return serviceComponentImpl;
1209 }
1210
1211
1219 @Override
1220 public ServiceComponent findByPrimaryKey(Serializable primaryKey)
1221 throws NoSuchModelException, SystemException {
1222 return findByPrimaryKey(((Long)primaryKey).longValue());
1223 }
1224
1225
1233 public ServiceComponent findByPrimaryKey(long serviceComponentId)
1234 throws NoSuchServiceComponentException, SystemException {
1235 ServiceComponent serviceComponent = fetchByPrimaryKey(serviceComponentId);
1236
1237 if (serviceComponent == null) {
1238 if (_log.isWarnEnabled()) {
1239 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1240 serviceComponentId);
1241 }
1242
1243 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1244 serviceComponentId);
1245 }
1246
1247 return serviceComponent;
1248 }
1249
1250
1257 @Override
1258 public ServiceComponent fetchByPrimaryKey(Serializable primaryKey)
1259 throws SystemException {
1260 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1261 }
1262
1263
1270 public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
1271 throws SystemException {
1272 ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1273 ServiceComponentImpl.class, serviceComponentId);
1274
1275 if (serviceComponent == _nullServiceComponent) {
1276 return null;
1277 }
1278
1279 if (serviceComponent == null) {
1280 Session session = null;
1281
1282 try {
1283 session = openSession();
1284
1285 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1286 Long.valueOf(serviceComponentId));
1287
1288 if (serviceComponent != null) {
1289 cacheResult(serviceComponent);
1290 }
1291 else {
1292 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1293 ServiceComponentImpl.class, serviceComponentId,
1294 _nullServiceComponent);
1295 }
1296 }
1297 catch (Exception e) {
1298 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1299 ServiceComponentImpl.class, serviceComponentId);
1300
1301 throw processException(e);
1302 }
1303 finally {
1304 closeSession(session);
1305 }
1306 }
1307
1308 return serviceComponent;
1309 }
1310
1311
1317 public List<ServiceComponent> findAll() throws SystemException {
1318 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1319 }
1320
1321
1333 public List<ServiceComponent> findAll(int start, int end)
1334 throws SystemException {
1335 return findAll(start, end, null);
1336 }
1337
1338
1351 public List<ServiceComponent> findAll(int start, int end,
1352 OrderByComparator orderByComparator) throws SystemException {
1353 boolean pagination = true;
1354 FinderPath finderPath = null;
1355 Object[] finderArgs = null;
1356
1357 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1358 (orderByComparator == null)) {
1359 pagination = false;
1360 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1361 finderArgs = FINDER_ARGS_EMPTY;
1362 }
1363 else {
1364 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1365 finderArgs = new Object[] { start, end, orderByComparator };
1366 }
1367
1368 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(finderPath,
1369 finderArgs, this);
1370
1371 if (list == null) {
1372 StringBundler query = null;
1373 String sql = null;
1374
1375 if (orderByComparator != null) {
1376 query = new StringBundler(2 +
1377 (orderByComparator.getOrderByFields().length * 3));
1378
1379 query.append(_SQL_SELECT_SERVICECOMPONENT);
1380
1381 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1382 orderByComparator);
1383
1384 sql = query.toString();
1385 }
1386 else {
1387 sql = _SQL_SELECT_SERVICECOMPONENT;
1388
1389 if (pagination) {
1390 sql = sql.concat(ServiceComponentModelImpl.ORDER_BY_JPQL);
1391 }
1392 }
1393
1394 Session session = null;
1395
1396 try {
1397 session = openSession();
1398
1399 Query q = session.createQuery(sql);
1400
1401 if (!pagination) {
1402 list = (List<ServiceComponent>)QueryUtil.list(q,
1403 getDialect(), start, end, false);
1404
1405 Collections.sort(list);
1406
1407 list = new UnmodifiableList<ServiceComponent>(list);
1408 }
1409 else {
1410 list = (List<ServiceComponent>)QueryUtil.list(q,
1411 getDialect(), start, end);
1412 }
1413
1414 cacheResult(list);
1415
1416 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1417 }
1418 catch (Exception e) {
1419 FinderCacheUtil.removeResult(finderPath, finderArgs);
1420
1421 throw processException(e);
1422 }
1423 finally {
1424 closeSession(session);
1425 }
1426 }
1427
1428 return list;
1429 }
1430
1431
1436 public void removeAll() throws SystemException {
1437 for (ServiceComponent serviceComponent : findAll()) {
1438 remove(serviceComponent);
1439 }
1440 }
1441
1442
1448 public int countAll() throws SystemException {
1449 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1450 FINDER_ARGS_EMPTY, this);
1451
1452 if (count == null) {
1453 Session session = null;
1454
1455 try {
1456 session = openSession();
1457
1458 Query q = session.createQuery(_SQL_COUNT_SERVICECOMPONENT);
1459
1460 count = (Long)q.uniqueResult();
1461
1462 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1463 FINDER_ARGS_EMPTY, count);
1464 }
1465 catch (Exception e) {
1466 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1467 FINDER_ARGS_EMPTY);
1468
1469 throw processException(e);
1470 }
1471 finally {
1472 closeSession(session);
1473 }
1474 }
1475
1476 return count.intValue();
1477 }
1478
1479
1482 public void afterPropertiesSet() {
1483 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1484 com.liferay.portal.util.PropsUtil.get(
1485 "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1486
1487 if (listenerClassNames.length > 0) {
1488 try {
1489 List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1490
1491 for (String listenerClassName : listenerClassNames) {
1492 listenersList.add((ModelListener<ServiceComponent>)InstanceFactory.newInstance(
1493 listenerClassName));
1494 }
1495
1496 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1497 }
1498 catch (Exception e) {
1499 _log.error(e);
1500 }
1501 }
1502 }
1503
1504 public void destroy() {
1505 EntityCacheUtil.removeCache(ServiceComponentImpl.class.getName());
1506 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1507 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1508 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1509 }
1510
1511 private static final String _SQL_SELECT_SERVICECOMPONENT = "SELECT serviceComponent FROM ServiceComponent serviceComponent";
1512 private static final String _SQL_SELECT_SERVICECOMPONENT_WHERE = "SELECT serviceComponent FROM ServiceComponent serviceComponent WHERE ";
1513 private static final String _SQL_COUNT_SERVICECOMPONENT = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent";
1514 private static final String _SQL_COUNT_SERVICECOMPONENT_WHERE = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent WHERE ";
1515 private static final String _ORDER_BY_ENTITY_ALIAS = "serviceComponent.";
1516 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ServiceComponent exists with the primary key ";
1517 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ServiceComponent exists with the key {";
1518 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1519 private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1520 private static ServiceComponent _nullServiceComponent = new ServiceComponentImpl() {
1521 @Override
1522 public Object clone() {
1523 return this;
1524 }
1525
1526 @Override
1527 public CacheModel<ServiceComponent> toCacheModel() {
1528 return _nullServiceComponentCacheModel;
1529 }
1530 };
1531
1532 private static CacheModel<ServiceComponent> _nullServiceComponentCacheModel = new CacheModel<ServiceComponent>() {
1533 public ServiceComponent toEntityModel() {
1534 return _nullServiceComponent;
1535 }
1536 };
1537 }