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