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.SetUtil;
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 import java.util.Set;
051
052
064 public class ServiceComponentPersistenceImpl extends BasePersistenceImpl<ServiceComponent>
065 implements ServiceComponentPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ServiceComponentImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
077 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
078 ServiceComponentImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079 "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
081 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
082 ServiceComponentImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
085 ServiceComponentModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_BUILDNAMESPACE =
088 new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
089 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
090 ServiceComponentImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findByBuildNamespace",
092 new String[] {
093 String.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE =
099 new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
100 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
101 ServiceComponentImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByBuildNamespace",
103 new String[] { String.class.getName() },
104 ServiceComponentModelImpl.BUILDNAMESPACE_COLUMN_BITMASK |
105 ServiceComponentModelImpl.BUILDNUMBER_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
107 ServiceComponentModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByBuildNamespace",
109 new String[] { String.class.getName() });
110
111
118 @Override
119 public List<ServiceComponent> findByBuildNamespace(String buildNamespace)
120 throws SystemException {
121 return findByBuildNamespace(buildNamespace, QueryUtil.ALL_POS,
122 QueryUtil.ALL_POS, null);
123 }
124
125
138 @Override
139 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
140 int start, int end) throws SystemException {
141 return findByBuildNamespace(buildNamespace, start, end, null);
142 }
143
144
158 @Override
159 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
160 int start, int end, OrderByComparator orderByComparator)
161 throws SystemException {
162 boolean pagination = true;
163 FinderPath finderPath = null;
164 Object[] finderArgs = null;
165
166 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
167 (orderByComparator == null)) {
168 pagination = false;
169 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE;
170 finderArgs = new Object[] { buildNamespace };
171 }
172 else {
173 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BUILDNAMESPACE;
174 finderArgs = new Object[] {
175 buildNamespace,
176
177 start, end, orderByComparator
178 };
179 }
180
181 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(finderPath,
182 finderArgs, this);
183
184 if ((list != null) && !list.isEmpty()) {
185 for (ServiceComponent serviceComponent : list) {
186 if (!Validator.equals(buildNamespace,
187 serviceComponent.getBuildNamespace())) {
188 list = null;
189
190 break;
191 }
192 }
193 }
194
195 if (list == null) {
196 StringBundler query = null;
197
198 if (orderByComparator != null) {
199 query = new StringBundler(3 +
200 (orderByComparator.getOrderByFields().length * 3));
201 }
202 else {
203 query = new StringBundler(3);
204 }
205
206 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
207
208 boolean bindBuildNamespace = false;
209
210 if (buildNamespace == null) {
211 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
212 }
213 else if (buildNamespace.equals(StringPool.BLANK)) {
214 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
215 }
216 else {
217 bindBuildNamespace = true;
218
219 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
220 }
221
222 if (orderByComparator != null) {
223 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
224 orderByComparator);
225 }
226 else
227 if (pagination) {
228 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
229 }
230
231 String sql = query.toString();
232
233 Session session = null;
234
235 try {
236 session = openSession();
237
238 Query q = session.createQuery(sql);
239
240 QueryPos qPos = QueryPos.getInstance(q);
241
242 if (bindBuildNamespace) {
243 qPos.add(buildNamespace);
244 }
245
246 if (!pagination) {
247 list = (List<ServiceComponent>)QueryUtil.list(q,
248 getDialect(), start, end, false);
249
250 Collections.sort(list);
251
252 list = new UnmodifiableList<ServiceComponent>(list);
253 }
254 else {
255 list = (List<ServiceComponent>)QueryUtil.list(q,
256 getDialect(), start, end);
257 }
258
259 cacheResult(list);
260
261 FinderCacheUtil.putResult(finderPath, finderArgs, list);
262 }
263 catch (Exception e) {
264 FinderCacheUtil.removeResult(finderPath, finderArgs);
265
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271 }
272
273 return list;
274 }
275
276
285 @Override
286 public ServiceComponent findByBuildNamespace_First(String buildNamespace,
287 OrderByComparator orderByComparator)
288 throws NoSuchServiceComponentException, SystemException {
289 ServiceComponent serviceComponent = fetchByBuildNamespace_First(buildNamespace,
290 orderByComparator);
291
292 if (serviceComponent != null) {
293 return serviceComponent;
294 }
295
296 StringBundler msg = new StringBundler(4);
297
298 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
299
300 msg.append("buildNamespace=");
301 msg.append(buildNamespace);
302
303 msg.append(StringPool.CLOSE_CURLY_BRACE);
304
305 throw new NoSuchServiceComponentException(msg.toString());
306 }
307
308
316 @Override
317 public ServiceComponent fetchByBuildNamespace_First(String buildNamespace,
318 OrderByComparator orderByComparator) throws SystemException {
319 List<ServiceComponent> list = findByBuildNamespace(buildNamespace, 0,
320 1, orderByComparator);
321
322 if (!list.isEmpty()) {
323 return list.get(0);
324 }
325
326 return null;
327 }
328
329
338 @Override
339 public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
340 OrderByComparator orderByComparator)
341 throws NoSuchServiceComponentException, SystemException {
342 ServiceComponent serviceComponent = fetchByBuildNamespace_Last(buildNamespace,
343 orderByComparator);
344
345 if (serviceComponent != null) {
346 return serviceComponent;
347 }
348
349 StringBundler msg = new StringBundler(4);
350
351 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
352
353 msg.append("buildNamespace=");
354 msg.append(buildNamespace);
355
356 msg.append(StringPool.CLOSE_CURLY_BRACE);
357
358 throw new NoSuchServiceComponentException(msg.toString());
359 }
360
361
369 @Override
370 public ServiceComponent fetchByBuildNamespace_Last(String buildNamespace,
371 OrderByComparator orderByComparator) throws SystemException {
372 int count = countByBuildNamespace(buildNamespace);
373
374 if (count == 0) {
375 return null;
376 }
377
378 List<ServiceComponent> list = findByBuildNamespace(buildNamespace,
379 count - 1, count, orderByComparator);
380
381 if (!list.isEmpty()) {
382 return list.get(0);
383 }
384
385 return null;
386 }
387
388
398 @Override
399 public ServiceComponent[] findByBuildNamespace_PrevAndNext(
400 long serviceComponentId, String buildNamespace,
401 OrderByComparator orderByComparator)
402 throws NoSuchServiceComponentException, SystemException {
403 ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
404
405 Session session = null;
406
407 try {
408 session = openSession();
409
410 ServiceComponent[] array = new ServiceComponentImpl[3];
411
412 array[0] = getByBuildNamespace_PrevAndNext(session,
413 serviceComponent, buildNamespace, orderByComparator, true);
414
415 array[1] = serviceComponent;
416
417 array[2] = getByBuildNamespace_PrevAndNext(session,
418 serviceComponent, buildNamespace, orderByComparator, false);
419
420 return array;
421 }
422 catch (Exception e) {
423 throw processException(e);
424 }
425 finally {
426 closeSession(session);
427 }
428 }
429
430 protected ServiceComponent getByBuildNamespace_PrevAndNext(
431 Session session, ServiceComponent serviceComponent,
432 String buildNamespace, OrderByComparator orderByComparator,
433 boolean previous) {
434 StringBundler query = null;
435
436 if (orderByComparator != null) {
437 query = new StringBundler(6 +
438 (orderByComparator.getOrderByFields().length * 6));
439 }
440 else {
441 query = new StringBundler(3);
442 }
443
444 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
445
446 boolean bindBuildNamespace = false;
447
448 if (buildNamespace == null) {
449 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
450 }
451 else if (buildNamespace.equals(StringPool.BLANK)) {
452 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
453 }
454 else {
455 bindBuildNamespace = true;
456
457 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
458 }
459
460 if (orderByComparator != null) {
461 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
462
463 if (orderByConditionFields.length > 0) {
464 query.append(WHERE_AND);
465 }
466
467 for (int i = 0; i < orderByConditionFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByConditionFields[i]);
470
471 if ((i + 1) < orderByConditionFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(WHERE_GREATER_THAN_HAS_NEXT);
474 }
475 else {
476 query.append(WHERE_LESSER_THAN_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(WHERE_GREATER_THAN);
482 }
483 else {
484 query.append(WHERE_LESSER_THAN);
485 }
486 }
487 }
488
489 query.append(ORDER_BY_CLAUSE);
490
491 String[] orderByFields = orderByComparator.getOrderByFields();
492
493 for (int i = 0; i < orderByFields.length; i++) {
494 query.append(_ORDER_BY_ENTITY_ALIAS);
495 query.append(orderByFields[i]);
496
497 if ((i + 1) < orderByFields.length) {
498 if (orderByComparator.isAscending() ^ previous) {
499 query.append(ORDER_BY_ASC_HAS_NEXT);
500 }
501 else {
502 query.append(ORDER_BY_DESC_HAS_NEXT);
503 }
504 }
505 else {
506 if (orderByComparator.isAscending() ^ previous) {
507 query.append(ORDER_BY_ASC);
508 }
509 else {
510 query.append(ORDER_BY_DESC);
511 }
512 }
513 }
514 }
515 else {
516 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
517 }
518
519 String sql = query.toString();
520
521 Query q = session.createQuery(sql);
522
523 q.setFirstResult(0);
524 q.setMaxResults(2);
525
526 QueryPos qPos = QueryPos.getInstance(q);
527
528 if (bindBuildNamespace) {
529 qPos.add(buildNamespace);
530 }
531
532 if (orderByComparator != null) {
533 Object[] values = orderByComparator.getOrderByConditionValues(serviceComponent);
534
535 for (Object value : values) {
536 qPos.add(value);
537 }
538 }
539
540 List<ServiceComponent> list = q.list();
541
542 if (list.size() == 2) {
543 return list.get(1);
544 }
545 else {
546 return null;
547 }
548 }
549
550
556 @Override
557 public void removeByBuildNamespace(String buildNamespace)
558 throws SystemException {
559 for (ServiceComponent serviceComponent : findByBuildNamespace(
560 buildNamespace, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
561 remove(serviceComponent);
562 }
563 }
564
565
572 @Override
573 public int countByBuildNamespace(String buildNamespace)
574 throws SystemException {
575 FinderPath finderPath = FINDER_PATH_COUNT_BY_BUILDNAMESPACE;
576
577 Object[] finderArgs = new Object[] { buildNamespace };
578
579 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
580 this);
581
582 if (count == null) {
583 StringBundler query = new StringBundler(2);
584
585 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
586
587 boolean bindBuildNamespace = false;
588
589 if (buildNamespace == null) {
590 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
591 }
592 else if (buildNamespace.equals(StringPool.BLANK)) {
593 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
594 }
595 else {
596 bindBuildNamespace = true;
597
598 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
599 }
600
601 String sql = query.toString();
602
603 Session session = null;
604
605 try {
606 session = openSession();
607
608 Query q = session.createQuery(sql);
609
610 QueryPos qPos = QueryPos.getInstance(q);
611
612 if (bindBuildNamespace) {
613 qPos.add(buildNamespace);
614 }
615
616 count = (Long)q.uniqueResult();
617
618 FinderCacheUtil.putResult(finderPath, finderArgs, count);
619 }
620 catch (Exception e) {
621 FinderCacheUtil.removeResult(finderPath, finderArgs);
622
623 throw processException(e);
624 }
625 finally {
626 closeSession(session);
627 }
628 }
629
630 return count.intValue();
631 }
632
633 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL";
634 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ?";
635 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = '')";
636 public static final FinderPath FINDER_PATH_FETCH_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
637 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
638 ServiceComponentImpl.class, FINDER_CLASS_NAME_ENTITY,
639 "fetchByBNS_BNU",
640 new String[] { String.class.getName(), Long.class.getName() },
641 ServiceComponentModelImpl.BUILDNAMESPACE_COLUMN_BITMASK |
642 ServiceComponentModelImpl.BUILDNUMBER_COLUMN_BITMASK);
643 public static final FinderPath FINDER_PATH_COUNT_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
644 ServiceComponentModelImpl.FINDER_CACHE_ENABLED, Long.class,
645 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByBNS_BNU",
646 new String[] { String.class.getName(), Long.class.getName() });
647
648
657 @Override
658 public ServiceComponent findByBNS_BNU(String buildNamespace,
659 long buildNumber)
660 throws NoSuchServiceComponentException, SystemException {
661 ServiceComponent serviceComponent = fetchByBNS_BNU(buildNamespace,
662 buildNumber);
663
664 if (serviceComponent == null) {
665 StringBundler msg = new StringBundler(6);
666
667 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
668
669 msg.append("buildNamespace=");
670 msg.append(buildNamespace);
671
672 msg.append(", buildNumber=");
673 msg.append(buildNumber);
674
675 msg.append(StringPool.CLOSE_CURLY_BRACE);
676
677 if (_log.isWarnEnabled()) {
678 _log.warn(msg.toString());
679 }
680
681 throw new NoSuchServiceComponentException(msg.toString());
682 }
683
684 return serviceComponent;
685 }
686
687
695 @Override
696 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
697 long buildNumber) throws SystemException {
698 return fetchByBNS_BNU(buildNamespace, buildNumber, true);
699 }
700
701
710 @Override
711 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
712 long buildNumber, boolean retrieveFromCache) throws SystemException {
713 Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
714
715 Object result = null;
716
717 if (retrieveFromCache) {
718 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_BNS_BNU,
719 finderArgs, this);
720 }
721
722 if (result instanceof ServiceComponent) {
723 ServiceComponent serviceComponent = (ServiceComponent)result;
724
725 if (!Validator.equals(buildNamespace,
726 serviceComponent.getBuildNamespace()) ||
727 (buildNumber != serviceComponent.getBuildNumber())) {
728 result = null;
729 }
730 }
731
732 if (result == null) {
733 StringBundler query = new StringBundler(4);
734
735 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
736
737 boolean bindBuildNamespace = false;
738
739 if (buildNamespace == null) {
740 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
741 }
742 else if (buildNamespace.equals(StringPool.BLANK)) {
743 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
744 }
745 else {
746 bindBuildNamespace = true;
747
748 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
749 }
750
751 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
752
753 String sql = query.toString();
754
755 Session session = null;
756
757 try {
758 session = openSession();
759
760 Query q = session.createQuery(sql);
761
762 QueryPos qPos = QueryPos.getInstance(q);
763
764 if (bindBuildNamespace) {
765 qPos.add(buildNamespace);
766 }
767
768 qPos.add(buildNumber);
769
770 List<ServiceComponent> list = q.list();
771
772 if (list.isEmpty()) {
773 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
774 finderArgs, list);
775 }
776 else {
777 ServiceComponent serviceComponent = list.get(0);
778
779 result = serviceComponent;
780
781 cacheResult(serviceComponent);
782
783 if ((serviceComponent.getBuildNamespace() == null) ||
784 !serviceComponent.getBuildNamespace()
785 .equals(buildNamespace) ||
786 (serviceComponent.getBuildNumber() != buildNumber)) {
787 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
788 finderArgs, serviceComponent);
789 }
790 }
791 }
792 catch (Exception e) {
793 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
794 finderArgs);
795
796 throw processException(e);
797 }
798 finally {
799 closeSession(session);
800 }
801 }
802
803 if (result instanceof List<?>) {
804 return null;
805 }
806 else {
807 return (ServiceComponent)result;
808 }
809 }
810
811
819 @Override
820 public ServiceComponent removeByBNS_BNU(String buildNamespace,
821 long buildNumber)
822 throws NoSuchServiceComponentException, SystemException {
823 ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
824 buildNumber);
825
826 return remove(serviceComponent);
827 }
828
829
837 @Override
838 public int countByBNS_BNU(String buildNamespace, long buildNumber)
839 throws SystemException {
840 FinderPath finderPath = FINDER_PATH_COUNT_BY_BNS_BNU;
841
842 Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
843
844 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
845 this);
846
847 if (count == null) {
848 StringBundler query = new StringBundler(3);
849
850 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
851
852 boolean bindBuildNamespace = false;
853
854 if (buildNamespace == null) {
855 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
856 }
857 else if (buildNamespace.equals(StringPool.BLANK)) {
858 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
859 }
860 else {
861 bindBuildNamespace = true;
862
863 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
864 }
865
866 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
867
868 String sql = query.toString();
869
870 Session session = null;
871
872 try {
873 session = openSession();
874
875 Query q = session.createQuery(sql);
876
877 QueryPos qPos = QueryPos.getInstance(q);
878
879 if (bindBuildNamespace) {
880 qPos.add(buildNamespace);
881 }
882
883 qPos.add(buildNumber);
884
885 count = (Long)q.uniqueResult();
886
887 FinderCacheUtil.putResult(finderPath, finderArgs, count);
888 }
889 catch (Exception e) {
890 FinderCacheUtil.removeResult(finderPath, finderArgs);
891
892 throw processException(e);
893 }
894 finally {
895 closeSession(session);
896 }
897 }
898
899 return count.intValue();
900 }
901
902 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL AND ";
903 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ? AND ";
904 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = '') AND ";
905 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2 = "serviceComponent.buildNumber = ?";
906
907 public ServiceComponentPersistenceImpl() {
908 setModelClass(ServiceComponent.class);
909 }
910
911
916 @Override
917 public void cacheResult(ServiceComponent serviceComponent) {
918 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
919 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
920 serviceComponent);
921
922 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
923 new Object[] {
924 serviceComponent.getBuildNamespace(),
925 serviceComponent.getBuildNumber()
926 }, serviceComponent);
927
928 serviceComponent.resetOriginalValues();
929 }
930
931
936 @Override
937 public void cacheResult(List<ServiceComponent> serviceComponents) {
938 for (ServiceComponent serviceComponent : serviceComponents) {
939 if (EntityCacheUtil.getResult(
940 ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
941 ServiceComponentImpl.class,
942 serviceComponent.getPrimaryKey()) == null) {
943 cacheResult(serviceComponent);
944 }
945 else {
946 serviceComponent.resetOriginalValues();
947 }
948 }
949 }
950
951
958 @Override
959 public void clearCache() {
960 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
961 CacheRegistryUtil.clear(ServiceComponentImpl.class.getName());
962 }
963
964 EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
965
966 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
967 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
968 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
969 }
970
971
978 @Override
979 public void clearCache(ServiceComponent serviceComponent) {
980 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
981 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
982
983 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
984 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
985
986 clearUniqueFindersCache(serviceComponent);
987 }
988
989 @Override
990 public void clearCache(List<ServiceComponent> serviceComponents) {
991 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
992 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
993
994 for (ServiceComponent serviceComponent : serviceComponents) {
995 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
996 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
997
998 clearUniqueFindersCache(serviceComponent);
999 }
1000 }
1001
1002 protected void cacheUniqueFindersCache(ServiceComponent serviceComponent) {
1003 if (serviceComponent.isNew()) {
1004 Object[] args = new Object[] {
1005 serviceComponent.getBuildNamespace(),
1006 serviceComponent.getBuildNumber()
1007 };
1008
1009 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU, args,
1010 Long.valueOf(1));
1011 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU, args,
1012 serviceComponent);
1013 }
1014 else {
1015 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1016
1017 if ((serviceComponentModelImpl.getColumnBitmask() &
1018 FINDER_PATH_FETCH_BY_BNS_BNU.getColumnBitmask()) != 0) {
1019 Object[] args = new Object[] {
1020 serviceComponent.getBuildNamespace(),
1021 serviceComponent.getBuildNumber()
1022 };
1023
1024 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU, args,
1025 Long.valueOf(1));
1026 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU, args,
1027 serviceComponent);
1028 }
1029 }
1030 }
1031
1032 protected void clearUniqueFindersCache(ServiceComponent serviceComponent) {
1033 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1034
1035 Object[] args = new Object[] {
1036 serviceComponent.getBuildNamespace(),
1037 serviceComponent.getBuildNumber()
1038 };
1039
1040 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BNS_BNU, args);
1041 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU, args);
1042
1043 if ((serviceComponentModelImpl.getColumnBitmask() &
1044 FINDER_PATH_FETCH_BY_BNS_BNU.getColumnBitmask()) != 0) {
1045 args = new Object[] {
1046 serviceComponentModelImpl.getOriginalBuildNamespace(),
1047 serviceComponentModelImpl.getOriginalBuildNumber()
1048 };
1049
1050 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BNS_BNU, args);
1051 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU, args);
1052 }
1053 }
1054
1055
1061 @Override
1062 public ServiceComponent create(long serviceComponentId) {
1063 ServiceComponent serviceComponent = new ServiceComponentImpl();
1064
1065 serviceComponent.setNew(true);
1066 serviceComponent.setPrimaryKey(serviceComponentId);
1067
1068 return serviceComponent;
1069 }
1070
1071
1079 @Override
1080 public ServiceComponent remove(long serviceComponentId)
1081 throws NoSuchServiceComponentException, SystemException {
1082 return remove((Serializable)serviceComponentId);
1083 }
1084
1085
1093 @Override
1094 public ServiceComponent remove(Serializable primaryKey)
1095 throws NoSuchServiceComponentException, SystemException {
1096 Session session = null;
1097
1098 try {
1099 session = openSession();
1100
1101 ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1102 primaryKey);
1103
1104 if (serviceComponent == null) {
1105 if (_log.isWarnEnabled()) {
1106 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1107 }
1108
1109 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1110 primaryKey);
1111 }
1112
1113 return remove(serviceComponent);
1114 }
1115 catch (NoSuchServiceComponentException nsee) {
1116 throw nsee;
1117 }
1118 catch (Exception e) {
1119 throw processException(e);
1120 }
1121 finally {
1122 closeSession(session);
1123 }
1124 }
1125
1126 @Override
1127 protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
1128 throws SystemException {
1129 serviceComponent = toUnwrappedModel(serviceComponent);
1130
1131 Session session = null;
1132
1133 try {
1134 session = openSession();
1135
1136 if (!session.contains(serviceComponent)) {
1137 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1138 serviceComponent.getPrimaryKeyObj());
1139 }
1140
1141 if (serviceComponent != null) {
1142 session.delete(serviceComponent);
1143 }
1144 }
1145 catch (Exception e) {
1146 throw processException(e);
1147 }
1148 finally {
1149 closeSession(session);
1150 }
1151
1152 if (serviceComponent != null) {
1153 clearCache(serviceComponent);
1154 }
1155
1156 return serviceComponent;
1157 }
1158
1159 @Override
1160 public ServiceComponent updateImpl(
1161 com.liferay.portal.model.ServiceComponent serviceComponent)
1162 throws SystemException {
1163 serviceComponent = toUnwrappedModel(serviceComponent);
1164
1165 boolean isNew = serviceComponent.isNew();
1166
1167 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1168
1169 Session session = null;
1170
1171 try {
1172 session = openSession();
1173
1174 if (serviceComponent.isNew()) {
1175 session.save(serviceComponent);
1176
1177 serviceComponent.setNew(false);
1178 }
1179 else {
1180 session.merge(serviceComponent);
1181 }
1182 }
1183 catch (Exception e) {
1184 throw processException(e);
1185 }
1186 finally {
1187 closeSession(session);
1188 }
1189
1190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1191
1192 if (isNew || !ServiceComponentModelImpl.COLUMN_BITMASK_ENABLED) {
1193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1194 }
1195
1196 else {
1197 if ((serviceComponentModelImpl.getColumnBitmask() &
1198 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE.getColumnBitmask()) != 0) {
1199 Object[] args = new Object[] {
1200 serviceComponentModelImpl.getOriginalBuildNamespace()
1201 };
1202
1203 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1204 args);
1205 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE,
1206 args);
1207
1208 args = new Object[] {
1209 serviceComponentModelImpl.getBuildNamespace()
1210 };
1211
1212 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1213 args);
1214 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE,
1215 args);
1216 }
1217 }
1218
1219 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1220 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
1221 serviceComponent);
1222
1223 clearUniqueFindersCache(serviceComponent);
1224 cacheUniqueFindersCache(serviceComponent);
1225
1226 return serviceComponent;
1227 }
1228
1229 protected ServiceComponent toUnwrappedModel(
1230 ServiceComponent serviceComponent) {
1231 if (serviceComponent instanceof ServiceComponentImpl) {
1232 return serviceComponent;
1233 }
1234
1235 ServiceComponentImpl serviceComponentImpl = new ServiceComponentImpl();
1236
1237 serviceComponentImpl.setNew(serviceComponent.isNew());
1238 serviceComponentImpl.setPrimaryKey(serviceComponent.getPrimaryKey());
1239
1240 serviceComponentImpl.setServiceComponentId(serviceComponent.getServiceComponentId());
1241 serviceComponentImpl.setBuildNamespace(serviceComponent.getBuildNamespace());
1242 serviceComponentImpl.setBuildNumber(serviceComponent.getBuildNumber());
1243 serviceComponentImpl.setBuildDate(serviceComponent.getBuildDate());
1244 serviceComponentImpl.setData(serviceComponent.getData());
1245
1246 return serviceComponentImpl;
1247 }
1248
1249
1257 @Override
1258 public ServiceComponent findByPrimaryKey(Serializable primaryKey)
1259 throws NoSuchServiceComponentException, SystemException {
1260 ServiceComponent serviceComponent = fetchByPrimaryKey(primaryKey);
1261
1262 if (serviceComponent == null) {
1263 if (_log.isWarnEnabled()) {
1264 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1265 }
1266
1267 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1268 primaryKey);
1269 }
1270
1271 return serviceComponent;
1272 }
1273
1274
1282 @Override
1283 public ServiceComponent findByPrimaryKey(long serviceComponentId)
1284 throws NoSuchServiceComponentException, SystemException {
1285 return findByPrimaryKey((Serializable)serviceComponentId);
1286 }
1287
1288
1295 @Override
1296 public ServiceComponent fetchByPrimaryKey(Serializable primaryKey)
1297 throws SystemException {
1298 ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1299 ServiceComponentImpl.class, primaryKey);
1300
1301 if (serviceComponent == _nullServiceComponent) {
1302 return null;
1303 }
1304
1305 if (serviceComponent == null) {
1306 Session session = null;
1307
1308 try {
1309 session = openSession();
1310
1311 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1312 primaryKey);
1313
1314 if (serviceComponent != null) {
1315 cacheResult(serviceComponent);
1316 }
1317 else {
1318 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1319 ServiceComponentImpl.class, primaryKey,
1320 _nullServiceComponent);
1321 }
1322 }
1323 catch (Exception e) {
1324 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1325 ServiceComponentImpl.class, primaryKey);
1326
1327 throw processException(e);
1328 }
1329 finally {
1330 closeSession(session);
1331 }
1332 }
1333
1334 return serviceComponent;
1335 }
1336
1337
1344 @Override
1345 public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
1346 throws SystemException {
1347 return fetchByPrimaryKey((Serializable)serviceComponentId);
1348 }
1349
1350
1356 @Override
1357 public List<ServiceComponent> findAll() throws SystemException {
1358 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1359 }
1360
1361
1373 @Override
1374 public List<ServiceComponent> findAll(int start, int end)
1375 throws SystemException {
1376 return findAll(start, end, null);
1377 }
1378
1379
1392 @Override
1393 public List<ServiceComponent> findAll(int start, int end,
1394 OrderByComparator orderByComparator) throws SystemException {
1395 boolean pagination = true;
1396 FinderPath finderPath = null;
1397 Object[] finderArgs = null;
1398
1399 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1400 (orderByComparator == null)) {
1401 pagination = false;
1402 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1403 finderArgs = FINDER_ARGS_EMPTY;
1404 }
1405 else {
1406 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1407 finderArgs = new Object[] { start, end, orderByComparator };
1408 }
1409
1410 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(finderPath,
1411 finderArgs, this);
1412
1413 if (list == null) {
1414 StringBundler query = null;
1415 String sql = null;
1416
1417 if (orderByComparator != null) {
1418 query = new StringBundler(2 +
1419 (orderByComparator.getOrderByFields().length * 3));
1420
1421 query.append(_SQL_SELECT_SERVICECOMPONENT);
1422
1423 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1424 orderByComparator);
1425
1426 sql = query.toString();
1427 }
1428 else {
1429 sql = _SQL_SELECT_SERVICECOMPONENT;
1430
1431 if (pagination) {
1432 sql = sql.concat(ServiceComponentModelImpl.ORDER_BY_JPQL);
1433 }
1434 }
1435
1436 Session session = null;
1437
1438 try {
1439 session = openSession();
1440
1441 Query q = session.createQuery(sql);
1442
1443 if (!pagination) {
1444 list = (List<ServiceComponent>)QueryUtil.list(q,
1445 getDialect(), start, end, false);
1446
1447 Collections.sort(list);
1448
1449 list = new UnmodifiableList<ServiceComponent>(list);
1450 }
1451 else {
1452 list = (List<ServiceComponent>)QueryUtil.list(q,
1453 getDialect(), start, end);
1454 }
1455
1456 cacheResult(list);
1457
1458 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1459 }
1460 catch (Exception e) {
1461 FinderCacheUtil.removeResult(finderPath, finderArgs);
1462
1463 throw processException(e);
1464 }
1465 finally {
1466 closeSession(session);
1467 }
1468 }
1469
1470 return list;
1471 }
1472
1473
1478 @Override
1479 public void removeAll() throws SystemException {
1480 for (ServiceComponent serviceComponent : findAll()) {
1481 remove(serviceComponent);
1482 }
1483 }
1484
1485
1491 @Override
1492 public int countAll() throws SystemException {
1493 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1494 FINDER_ARGS_EMPTY, this);
1495
1496 if (count == null) {
1497 Session session = null;
1498
1499 try {
1500 session = openSession();
1501
1502 Query q = session.createQuery(_SQL_COUNT_SERVICECOMPONENT);
1503
1504 count = (Long)q.uniqueResult();
1505
1506 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1507 FINDER_ARGS_EMPTY, count);
1508 }
1509 catch (Exception e) {
1510 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1511 FINDER_ARGS_EMPTY);
1512
1513 throw processException(e);
1514 }
1515 finally {
1516 closeSession(session);
1517 }
1518 }
1519
1520 return count.intValue();
1521 }
1522
1523 @Override
1524 protected Set<String> getBadColumnNames() {
1525 return _badColumnNames;
1526 }
1527
1528
1531 public void afterPropertiesSet() {
1532 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1533 com.liferay.portal.util.PropsUtil.get(
1534 "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1535
1536 if (listenerClassNames.length > 0) {
1537 try {
1538 List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1539
1540 for (String listenerClassName : listenerClassNames) {
1541 listenersList.add((ModelListener<ServiceComponent>)InstanceFactory.newInstance(
1542 getClassLoader(), listenerClassName));
1543 }
1544
1545 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1546 }
1547 catch (Exception e) {
1548 _log.error(e);
1549 }
1550 }
1551 }
1552
1553 public void destroy() {
1554 EntityCacheUtil.removeCache(ServiceComponentImpl.class.getName());
1555 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1556 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1557 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1558 }
1559
1560 private static final String _SQL_SELECT_SERVICECOMPONENT = "SELECT serviceComponent FROM ServiceComponent serviceComponent";
1561 private static final String _SQL_SELECT_SERVICECOMPONENT_WHERE = "SELECT serviceComponent FROM ServiceComponent serviceComponent WHERE ";
1562 private static final String _SQL_COUNT_SERVICECOMPONENT = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent";
1563 private static final String _SQL_COUNT_SERVICECOMPONENT_WHERE = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent WHERE ";
1564 private static final String _ORDER_BY_ENTITY_ALIAS = "serviceComponent.";
1565 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ServiceComponent exists with the primary key ";
1566 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ServiceComponent exists with the key {";
1567 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1568 private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1569 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1570 "data"
1571 });
1572 private static ServiceComponent _nullServiceComponent = new ServiceComponentImpl() {
1573 @Override
1574 public Object clone() {
1575 return this;
1576 }
1577
1578 @Override
1579 public CacheModel<ServiceComponent> toCacheModel() {
1580 return _nullServiceComponentCacheModel;
1581 }
1582 };
1583
1584 private static CacheModel<ServiceComponent> _nullServiceComponentCacheModel = new CacheModel<ServiceComponent>() {
1585 @Override
1586 public ServiceComponent toEntityModel() {
1587 return _nullServiceComponent;
1588 }
1589 };
1590 }