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
912 @Override
913 public void cacheResult(ServiceComponent serviceComponent) {
914 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
915 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
916 serviceComponent);
917
918 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
919 new Object[] {
920 serviceComponent.getBuildNamespace(),
921 serviceComponent.getBuildNumber()
922 }, serviceComponent);
923
924 serviceComponent.resetOriginalValues();
925 }
926
927
932 @Override
933 public void cacheResult(List<ServiceComponent> serviceComponents) {
934 for (ServiceComponent serviceComponent : serviceComponents) {
935 if (EntityCacheUtil.getResult(
936 ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
937 ServiceComponentImpl.class,
938 serviceComponent.getPrimaryKey()) == null) {
939 cacheResult(serviceComponent);
940 }
941 else {
942 serviceComponent.resetOriginalValues();
943 }
944 }
945 }
946
947
954 @Override
955 public void clearCache() {
956 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
957 CacheRegistryUtil.clear(ServiceComponentImpl.class.getName());
958 }
959
960 EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
961
962 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
963 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
964 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
965 }
966
967
974 @Override
975 public void clearCache(ServiceComponent serviceComponent) {
976 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
977 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
978
979 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
980 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
981
982 clearUniqueFindersCache(serviceComponent);
983 }
984
985 @Override
986 public void clearCache(List<ServiceComponent> serviceComponents) {
987 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
988 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
989
990 for (ServiceComponent serviceComponent : serviceComponents) {
991 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
992 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
993
994 clearUniqueFindersCache(serviceComponent);
995 }
996 }
997
998 protected void cacheUniqueFindersCache(ServiceComponent serviceComponent) {
999 if (serviceComponent.isNew()) {
1000 Object[] args = new Object[] {
1001 serviceComponent.getBuildNamespace(),
1002 serviceComponent.getBuildNumber()
1003 };
1004
1005 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU, args,
1006 Long.valueOf(1));
1007 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU, args,
1008 serviceComponent);
1009 }
1010 else {
1011 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1012
1013 if ((serviceComponentModelImpl.getColumnBitmask() &
1014 FINDER_PATH_FETCH_BY_BNS_BNU.getColumnBitmask()) != 0) {
1015 Object[] args = new Object[] {
1016 serviceComponent.getBuildNamespace(),
1017 serviceComponent.getBuildNumber()
1018 };
1019
1020 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU, args,
1021 Long.valueOf(1));
1022 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU, args,
1023 serviceComponent);
1024 }
1025 }
1026 }
1027
1028 protected void clearUniqueFindersCache(ServiceComponent serviceComponent) {
1029 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1030
1031 Object[] args = new Object[] {
1032 serviceComponent.getBuildNamespace(),
1033 serviceComponent.getBuildNumber()
1034 };
1035
1036 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BNS_BNU, args);
1037 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU, args);
1038
1039 if ((serviceComponentModelImpl.getColumnBitmask() &
1040 FINDER_PATH_FETCH_BY_BNS_BNU.getColumnBitmask()) != 0) {
1041 args = new Object[] {
1042 serviceComponentModelImpl.getOriginalBuildNamespace(),
1043 serviceComponentModelImpl.getOriginalBuildNumber()
1044 };
1045
1046 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BNS_BNU, args);
1047 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU, args);
1048 }
1049 }
1050
1051
1057 @Override
1058 public ServiceComponent create(long serviceComponentId) {
1059 ServiceComponent serviceComponent = new ServiceComponentImpl();
1060
1061 serviceComponent.setNew(true);
1062 serviceComponent.setPrimaryKey(serviceComponentId);
1063
1064 return serviceComponent;
1065 }
1066
1067
1075 @Override
1076 public ServiceComponent remove(long serviceComponentId)
1077 throws NoSuchServiceComponentException, SystemException {
1078 return remove((Serializable)serviceComponentId);
1079 }
1080
1081
1089 @Override
1090 public ServiceComponent remove(Serializable primaryKey)
1091 throws NoSuchServiceComponentException, SystemException {
1092 Session session = null;
1093
1094 try {
1095 session = openSession();
1096
1097 ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1098 primaryKey);
1099
1100 if (serviceComponent == null) {
1101 if (_log.isWarnEnabled()) {
1102 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1103 }
1104
1105 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1106 primaryKey);
1107 }
1108
1109 return remove(serviceComponent);
1110 }
1111 catch (NoSuchServiceComponentException nsee) {
1112 throw nsee;
1113 }
1114 catch (Exception e) {
1115 throw processException(e);
1116 }
1117 finally {
1118 closeSession(session);
1119 }
1120 }
1121
1122 @Override
1123 protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
1124 throws SystemException {
1125 serviceComponent = toUnwrappedModel(serviceComponent);
1126
1127 Session session = null;
1128
1129 try {
1130 session = openSession();
1131
1132 if (!session.contains(serviceComponent)) {
1133 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1134 serviceComponent.getPrimaryKeyObj());
1135 }
1136
1137 if (serviceComponent != null) {
1138 session.delete(serviceComponent);
1139 }
1140 }
1141 catch (Exception e) {
1142 throw processException(e);
1143 }
1144 finally {
1145 closeSession(session);
1146 }
1147
1148 if (serviceComponent != null) {
1149 clearCache(serviceComponent);
1150 }
1151
1152 return serviceComponent;
1153 }
1154
1155 @Override
1156 public ServiceComponent updateImpl(
1157 com.liferay.portal.model.ServiceComponent serviceComponent)
1158 throws SystemException {
1159 serviceComponent = toUnwrappedModel(serviceComponent);
1160
1161 boolean isNew = serviceComponent.isNew();
1162
1163 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
1164
1165 Session session = null;
1166
1167 try {
1168 session = openSession();
1169
1170 if (serviceComponent.isNew()) {
1171 session.save(serviceComponent);
1172
1173 serviceComponent.setNew(false);
1174 }
1175 else {
1176 session.merge(serviceComponent);
1177 }
1178 }
1179 catch (Exception e) {
1180 throw processException(e);
1181 }
1182 finally {
1183 closeSession(session);
1184 }
1185
1186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1187
1188 if (isNew || !ServiceComponentModelImpl.COLUMN_BITMASK_ENABLED) {
1189 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1190 }
1191
1192 else {
1193 if ((serviceComponentModelImpl.getColumnBitmask() &
1194 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE.getColumnBitmask()) != 0) {
1195 Object[] args = new Object[] {
1196 serviceComponentModelImpl.getOriginalBuildNamespace()
1197 };
1198
1199 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1200 args);
1201 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE,
1202 args);
1203
1204 args = new Object[] {
1205 serviceComponentModelImpl.getBuildNamespace()
1206 };
1207
1208 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1209 args);
1210 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BUILDNAMESPACE,
1211 args);
1212 }
1213 }
1214
1215 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1216 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
1217 serviceComponent);
1218
1219 clearUniqueFindersCache(serviceComponent);
1220 cacheUniqueFindersCache(serviceComponent);
1221
1222 return serviceComponent;
1223 }
1224
1225 protected ServiceComponent toUnwrappedModel(
1226 ServiceComponent serviceComponent) {
1227 if (serviceComponent instanceof ServiceComponentImpl) {
1228 return serviceComponent;
1229 }
1230
1231 ServiceComponentImpl serviceComponentImpl = new ServiceComponentImpl();
1232
1233 serviceComponentImpl.setNew(serviceComponent.isNew());
1234 serviceComponentImpl.setPrimaryKey(serviceComponent.getPrimaryKey());
1235
1236 serviceComponentImpl.setServiceComponentId(serviceComponent.getServiceComponentId());
1237 serviceComponentImpl.setBuildNamespace(serviceComponent.getBuildNamespace());
1238 serviceComponentImpl.setBuildNumber(serviceComponent.getBuildNumber());
1239 serviceComponentImpl.setBuildDate(serviceComponent.getBuildDate());
1240 serviceComponentImpl.setData(serviceComponent.getData());
1241
1242 return serviceComponentImpl;
1243 }
1244
1245
1253 @Override
1254 public ServiceComponent findByPrimaryKey(Serializable primaryKey)
1255 throws NoSuchServiceComponentException, SystemException {
1256 ServiceComponent serviceComponent = fetchByPrimaryKey(primaryKey);
1257
1258 if (serviceComponent == null) {
1259 if (_log.isWarnEnabled()) {
1260 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1261 }
1262
1263 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1264 primaryKey);
1265 }
1266
1267 return serviceComponent;
1268 }
1269
1270
1278 @Override
1279 public ServiceComponent findByPrimaryKey(long serviceComponentId)
1280 throws NoSuchServiceComponentException, SystemException {
1281 return findByPrimaryKey((Serializable)serviceComponentId);
1282 }
1283
1284
1291 @Override
1292 public ServiceComponent fetchByPrimaryKey(Serializable primaryKey)
1293 throws SystemException {
1294 ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1295 ServiceComponentImpl.class, primaryKey);
1296
1297 if (serviceComponent == _nullServiceComponent) {
1298 return null;
1299 }
1300
1301 if (serviceComponent == null) {
1302 Session session = null;
1303
1304 try {
1305 session = openSession();
1306
1307 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
1308 primaryKey);
1309
1310 if (serviceComponent != null) {
1311 cacheResult(serviceComponent);
1312 }
1313 else {
1314 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1315 ServiceComponentImpl.class, primaryKey,
1316 _nullServiceComponent);
1317 }
1318 }
1319 catch (Exception e) {
1320 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
1321 ServiceComponentImpl.class, primaryKey);
1322
1323 throw processException(e);
1324 }
1325 finally {
1326 closeSession(session);
1327 }
1328 }
1329
1330 return serviceComponent;
1331 }
1332
1333
1340 @Override
1341 public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
1342 throws SystemException {
1343 return fetchByPrimaryKey((Serializable)serviceComponentId);
1344 }
1345
1346
1352 @Override
1353 public List<ServiceComponent> findAll() throws SystemException {
1354 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1355 }
1356
1357
1369 @Override
1370 public List<ServiceComponent> findAll(int start, int end)
1371 throws SystemException {
1372 return findAll(start, end, null);
1373 }
1374
1375
1388 @Override
1389 public List<ServiceComponent> findAll(int start, int end,
1390 OrderByComparator orderByComparator) throws SystemException {
1391 boolean pagination = true;
1392 FinderPath finderPath = null;
1393 Object[] finderArgs = null;
1394
1395 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1396 (orderByComparator == null)) {
1397 pagination = false;
1398 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1399 finderArgs = FINDER_ARGS_EMPTY;
1400 }
1401 else {
1402 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1403 finderArgs = new Object[] { start, end, orderByComparator };
1404 }
1405
1406 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(finderPath,
1407 finderArgs, this);
1408
1409 if (list == null) {
1410 StringBundler query = null;
1411 String sql = null;
1412
1413 if (orderByComparator != null) {
1414 query = new StringBundler(2 +
1415 (orderByComparator.getOrderByFields().length * 3));
1416
1417 query.append(_SQL_SELECT_SERVICECOMPONENT);
1418
1419 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1420 orderByComparator);
1421
1422 sql = query.toString();
1423 }
1424 else {
1425 sql = _SQL_SELECT_SERVICECOMPONENT;
1426
1427 if (pagination) {
1428 sql = sql.concat(ServiceComponentModelImpl.ORDER_BY_JPQL);
1429 }
1430 }
1431
1432 Session session = null;
1433
1434 try {
1435 session = openSession();
1436
1437 Query q = session.createQuery(sql);
1438
1439 if (!pagination) {
1440 list = (List<ServiceComponent>)QueryUtil.list(q,
1441 getDialect(), start, end, false);
1442
1443 Collections.sort(list);
1444
1445 list = new UnmodifiableList<ServiceComponent>(list);
1446 }
1447 else {
1448 list = (List<ServiceComponent>)QueryUtil.list(q,
1449 getDialect(), start, end);
1450 }
1451
1452 cacheResult(list);
1453
1454 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1455 }
1456 catch (Exception e) {
1457 FinderCacheUtil.removeResult(finderPath, finderArgs);
1458
1459 throw processException(e);
1460 }
1461 finally {
1462 closeSession(session);
1463 }
1464 }
1465
1466 return list;
1467 }
1468
1469
1474 @Override
1475 public void removeAll() throws SystemException {
1476 for (ServiceComponent serviceComponent : findAll()) {
1477 remove(serviceComponent);
1478 }
1479 }
1480
1481
1487 @Override
1488 public int countAll() throws SystemException {
1489 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1490 FINDER_ARGS_EMPTY, this);
1491
1492 if (count == null) {
1493 Session session = null;
1494
1495 try {
1496 session = openSession();
1497
1498 Query q = session.createQuery(_SQL_COUNT_SERVICECOMPONENT);
1499
1500 count = (Long)q.uniqueResult();
1501
1502 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1503 FINDER_ARGS_EMPTY, count);
1504 }
1505 catch (Exception e) {
1506 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1507 FINDER_ARGS_EMPTY);
1508
1509 throw processException(e);
1510 }
1511 finally {
1512 closeSession(session);
1513 }
1514 }
1515
1516 return count.intValue();
1517 }
1518
1519 @Override
1520 protected Set<String> getBadColumnNames() {
1521 return _badColumnNames;
1522 }
1523
1524
1527 public void afterPropertiesSet() {
1528 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1529 com.liferay.portal.util.PropsUtil.get(
1530 "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1531
1532 if (listenerClassNames.length > 0) {
1533 try {
1534 List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1535
1536 for (String listenerClassName : listenerClassNames) {
1537 listenersList.add((ModelListener<ServiceComponent>)InstanceFactory.newInstance(
1538 getClassLoader(), listenerClassName));
1539 }
1540
1541 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1542 }
1543 catch (Exception e) {
1544 _log.error(e);
1545 }
1546 }
1547 }
1548
1549 public void destroy() {
1550 EntityCacheUtil.removeCache(ServiceComponentImpl.class.getName());
1551 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1552 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1553 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1554 }
1555
1556 private static final String _SQL_SELECT_SERVICECOMPONENT = "SELECT serviceComponent FROM ServiceComponent serviceComponent";
1557 private static final String _SQL_SELECT_SERVICECOMPONENT_WHERE = "SELECT serviceComponent FROM ServiceComponent serviceComponent WHERE ";
1558 private static final String _SQL_COUNT_SERVICECOMPONENT = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent";
1559 private static final String _SQL_COUNT_SERVICECOMPONENT_WHERE = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent WHERE ";
1560 private static final String _ORDER_BY_ENTITY_ALIAS = "serviceComponent.";
1561 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ServiceComponent exists with the primary key ";
1562 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ServiceComponent exists with the key {";
1563 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1564 private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1565 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1566 "data"
1567 });
1568 private static ServiceComponent _nullServiceComponent = new ServiceComponentImpl() {
1569 @Override
1570 public Object clone() {
1571 return this;
1572 }
1573
1574 @Override
1575 public CacheModel<ServiceComponent> toCacheModel() {
1576 return _nullServiceComponentCacheModel;
1577 }
1578 };
1579
1580 private static CacheModel<ServiceComponent> _nullServiceComponentCacheModel = new CacheModel<ServiceComponent>() {
1581 @Override
1582 public ServiceComponent toEntityModel() {
1583 return _nullServiceComponent;
1584 }
1585 };
1586 }