1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.NoSuchServiceComponentException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.exception.SystemException;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.InstanceFactory;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringBundler;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.kernel.util.Validator;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.model.ServiceComponent;
40 import com.liferay.portal.model.impl.ServiceComponentImpl;
41 import com.liferay.portal.model.impl.ServiceComponentModelImpl;
42 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43
44 import java.io.Serializable;
45
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.List;
49
50
63 public class ServiceComponentPersistenceImpl extends BasePersistenceImpl<ServiceComponent>
64 implements ServiceComponentPersistence {
65 public static final String FINDER_CLASS_NAME_ENTITY = ServiceComponentImpl.class.getName();
66 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67 ".List";
68 public static final FinderPath FINDER_PATH_FIND_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
69 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
70 FINDER_CLASS_NAME_LIST, "findByBuildNamespace",
71 new String[] {
72 String.class.getName(),
73
74 "java.lang.Integer", "java.lang.Integer",
75 "com.liferay.portal.kernel.util.OrderByComparator"
76 });
77 public static final FinderPath FINDER_PATH_COUNT_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
78 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
79 FINDER_CLASS_NAME_LIST, "countByBuildNamespace",
80 new String[] { String.class.getName() });
81 public static final FinderPath FINDER_PATH_FETCH_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
82 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
83 FINDER_CLASS_NAME_ENTITY, "fetchByBNS_BNU",
84 new String[] { String.class.getName(), Long.class.getName() });
85 public static final FinderPath FINDER_PATH_COUNT_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
86 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
87 FINDER_CLASS_NAME_LIST, "countByBNS_BNU",
88 new String[] { String.class.getName(), Long.class.getName() });
89 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
90 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
91 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
92 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
93 ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
94 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
95
96 public void cacheResult(ServiceComponent serviceComponent) {
97 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
98 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
99 serviceComponent);
100
101 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
102 new Object[] {
103 serviceComponent.getBuildNamespace(),
104 new Long(serviceComponent.getBuildNumber())
105 }, serviceComponent);
106 }
107
108 public void cacheResult(List<ServiceComponent> serviceComponents) {
109 for (ServiceComponent serviceComponent : serviceComponents) {
110 if (EntityCacheUtil.getResult(
111 ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
112 ServiceComponentImpl.class,
113 serviceComponent.getPrimaryKey(), this) == null) {
114 cacheResult(serviceComponent);
115 }
116 }
117 }
118
119 public void clearCache() {
120 CacheRegistry.clear(ServiceComponentImpl.class.getName());
121 EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
122 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
123 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
124 }
125
126 public void clearCache(ServiceComponent serviceComponent) {
127 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
128 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
129
130 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
131 new Object[] {
132 serviceComponent.getBuildNamespace(),
133 new Long(serviceComponent.getBuildNumber())
134 });
135 }
136
137 public ServiceComponent create(long serviceComponentId) {
138 ServiceComponent serviceComponent = new ServiceComponentImpl();
139
140 serviceComponent.setNew(true);
141 serviceComponent.setPrimaryKey(serviceComponentId);
142
143 return serviceComponent;
144 }
145
146 public ServiceComponent remove(Serializable primaryKey)
147 throws NoSuchModelException, SystemException {
148 return remove(((Long)primaryKey).longValue());
149 }
150
151 public ServiceComponent remove(long serviceComponentId)
152 throws NoSuchServiceComponentException, SystemException {
153 Session session = null;
154
155 try {
156 session = openSession();
157
158 ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
159 new Long(serviceComponentId));
160
161 if (serviceComponent == null) {
162 if (_log.isWarnEnabled()) {
163 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
164 serviceComponentId);
165 }
166
167 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
168 serviceComponentId);
169 }
170
171 return remove(serviceComponent);
172 }
173 catch (NoSuchServiceComponentException nsee) {
174 throw nsee;
175 }
176 catch (Exception e) {
177 throw processException(e);
178 }
179 finally {
180 closeSession(session);
181 }
182 }
183
184 public ServiceComponent remove(ServiceComponent serviceComponent)
185 throws SystemException {
186 for (ModelListener<ServiceComponent> listener : listeners) {
187 listener.onBeforeRemove(serviceComponent);
188 }
189
190 serviceComponent = removeImpl(serviceComponent);
191
192 for (ModelListener<ServiceComponent> listener : listeners) {
193 listener.onAfterRemove(serviceComponent);
194 }
195
196 return serviceComponent;
197 }
198
199 protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
200 throws SystemException {
201 serviceComponent = toUnwrappedModel(serviceComponent);
202
203 Session session = null;
204
205 try {
206 session = openSession();
207
208 if (serviceComponent.isCachedModel() ||
209 BatchSessionUtil.isEnabled()) {
210 Object staleObject = session.get(ServiceComponentImpl.class,
211 serviceComponent.getPrimaryKeyObj());
212
213 if (staleObject != null) {
214 session.evict(staleObject);
215 }
216 }
217
218 session.delete(serviceComponent);
219
220 session.flush();
221 }
222 catch (Exception e) {
223 throw processException(e);
224 }
225 finally {
226 closeSession(session);
227 }
228
229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
230
231 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
232
233 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
234 new Object[] {
235 serviceComponentModelImpl.getOriginalBuildNamespace(),
236 new Long(serviceComponentModelImpl.getOriginalBuildNumber())
237 });
238
239 EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
240 ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
241
242 return serviceComponent;
243 }
244
245 public ServiceComponent updateImpl(
246 com.liferay.portal.model.ServiceComponent serviceComponent,
247 boolean merge) throws SystemException {
248 serviceComponent = toUnwrappedModel(serviceComponent);
249
250 boolean isNew = serviceComponent.isNew();
251
252 ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
253
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 BatchSessionUtil.update(session, serviceComponent, merge);
260
261 serviceComponent.setNew(false);
262 }
263 catch (Exception e) {
264 throw processException(e);
265 }
266 finally {
267 closeSession(session);
268 }
269
270 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
271
272 EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
273 ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
274 serviceComponent);
275
276 if (!isNew &&
277 (!Validator.equals(serviceComponent.getBuildNamespace(),
278 serviceComponentModelImpl.getOriginalBuildNamespace()) ||
279 (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
280 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
281 new Object[] {
282 serviceComponentModelImpl.getOriginalBuildNamespace(),
283 new Long(serviceComponentModelImpl.getOriginalBuildNumber())
284 });
285 }
286
287 if (isNew ||
288 (!Validator.equals(serviceComponent.getBuildNamespace(),
289 serviceComponentModelImpl.getOriginalBuildNamespace()) ||
290 (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
291 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
292 new Object[] {
293 serviceComponent.getBuildNamespace(),
294 new Long(serviceComponent.getBuildNumber())
295 }, serviceComponent);
296 }
297
298 return serviceComponent;
299 }
300
301 protected ServiceComponent toUnwrappedModel(
302 ServiceComponent serviceComponent) {
303 if (serviceComponent instanceof ServiceComponentImpl) {
304 return serviceComponent;
305 }
306
307 ServiceComponentImpl serviceComponentImpl = new ServiceComponentImpl();
308
309 serviceComponentImpl.setNew(serviceComponent.isNew());
310 serviceComponentImpl.setPrimaryKey(serviceComponent.getPrimaryKey());
311
312 serviceComponentImpl.setServiceComponentId(serviceComponent.getServiceComponentId());
313 serviceComponentImpl.setBuildNamespace(serviceComponent.getBuildNamespace());
314 serviceComponentImpl.setBuildNumber(serviceComponent.getBuildNumber());
315 serviceComponentImpl.setBuildDate(serviceComponent.getBuildDate());
316 serviceComponentImpl.setData(serviceComponent.getData());
317
318 return serviceComponentImpl;
319 }
320
321 public ServiceComponent findByPrimaryKey(Serializable primaryKey)
322 throws NoSuchModelException, SystemException {
323 return findByPrimaryKey(((Long)primaryKey).longValue());
324 }
325
326 public ServiceComponent findByPrimaryKey(long serviceComponentId)
327 throws NoSuchServiceComponentException, SystemException {
328 ServiceComponent serviceComponent = fetchByPrimaryKey(serviceComponentId);
329
330 if (serviceComponent == null) {
331 if (_log.isWarnEnabled()) {
332 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
333 serviceComponentId);
334 }
335
336 throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
337 serviceComponentId);
338 }
339
340 return serviceComponent;
341 }
342
343 public ServiceComponent fetchByPrimaryKey(Serializable primaryKey)
344 throws SystemException {
345 return fetchByPrimaryKey(((Long)primaryKey).longValue());
346 }
347
348 public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
349 throws SystemException {
350 ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
351 ServiceComponentImpl.class, serviceComponentId, this);
352
353 if (serviceComponent == null) {
354 Session session = null;
355
356 try {
357 session = openSession();
358
359 serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
360 new Long(serviceComponentId));
361 }
362 catch (Exception e) {
363 throw processException(e);
364 }
365 finally {
366 if (serviceComponent != null) {
367 cacheResult(serviceComponent);
368 }
369
370 closeSession(session);
371 }
372 }
373
374 return serviceComponent;
375 }
376
377 public List<ServiceComponent> findByBuildNamespace(String buildNamespace)
378 throws SystemException {
379 return findByBuildNamespace(buildNamespace, QueryUtil.ALL_POS,
380 QueryUtil.ALL_POS, null);
381 }
382
383 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
384 int start, int end) throws SystemException {
385 return findByBuildNamespace(buildNamespace, start, end, null);
386 }
387
388 public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
389 int start, int end, OrderByComparator orderByComparator)
390 throws SystemException {
391 Object[] finderArgs = new Object[] {
392 buildNamespace,
393
394 String.valueOf(start), String.valueOf(end),
395 String.valueOf(orderByComparator)
396 };
397
398 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
399 finderArgs, this);
400
401 if (list == null) {
402 Session session = null;
403
404 try {
405 session = openSession();
406
407 StringBundler query = null;
408
409 if (orderByComparator != null) {
410 query = new StringBundler(3 +
411 (orderByComparator.getOrderByFields().length * 3));
412 }
413 else {
414 query = new StringBundler(3);
415 }
416
417 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
418
419 if (buildNamespace == null) {
420 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
421 }
422 else {
423 if (buildNamespace.equals(StringPool.BLANK)) {
424 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
425 }
426 else {
427 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
428 }
429 }
430
431 if (orderByComparator != null) {
432 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
433 orderByComparator);
434 }
435
436 else {
437 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
438 }
439
440 String sql = query.toString();
441
442 Query q = session.createQuery(sql);
443
444 QueryPos qPos = QueryPos.getInstance(q);
445
446 if (buildNamespace != null) {
447 qPos.add(buildNamespace);
448 }
449
450 list = (List<ServiceComponent>)QueryUtil.list(q, getDialect(),
451 start, end);
452 }
453 catch (Exception e) {
454 throw processException(e);
455 }
456 finally {
457 if (list == null) {
458 list = new ArrayList<ServiceComponent>();
459 }
460
461 cacheResult(list);
462
463 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
464 finderArgs, list);
465
466 closeSession(session);
467 }
468 }
469
470 return list;
471 }
472
473 public ServiceComponent findByBuildNamespace_First(String buildNamespace,
474 OrderByComparator orderByComparator)
475 throws NoSuchServiceComponentException, SystemException {
476 List<ServiceComponent> list = findByBuildNamespace(buildNamespace, 0,
477 1, orderByComparator);
478
479 if (list.isEmpty()) {
480 StringBundler msg = new StringBundler(4);
481
482 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
483
484 msg.append("buildNamespace=");
485 msg.append(buildNamespace);
486
487 msg.append(StringPool.CLOSE_CURLY_BRACE);
488
489 throw new NoSuchServiceComponentException(msg.toString());
490 }
491 else {
492 return list.get(0);
493 }
494 }
495
496 public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
497 OrderByComparator orderByComparator)
498 throws NoSuchServiceComponentException, SystemException {
499 int count = countByBuildNamespace(buildNamespace);
500
501 List<ServiceComponent> list = findByBuildNamespace(buildNamespace,
502 count - 1, count, orderByComparator);
503
504 if (list.isEmpty()) {
505 StringBundler msg = new StringBundler(4);
506
507 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
508
509 msg.append("buildNamespace=");
510 msg.append(buildNamespace);
511
512 msg.append(StringPool.CLOSE_CURLY_BRACE);
513
514 throw new NoSuchServiceComponentException(msg.toString());
515 }
516 else {
517 return list.get(0);
518 }
519 }
520
521 public ServiceComponent[] findByBuildNamespace_PrevAndNext(
522 long serviceComponentId, String buildNamespace,
523 OrderByComparator orderByComparator)
524 throws NoSuchServiceComponentException, SystemException {
525 ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
526
527 Session session = null;
528
529 try {
530 session = openSession();
531
532 ServiceComponent[] array = new ServiceComponentImpl[3];
533
534 array[0] = getByBuildNamespace_PrevAndNext(session,
535 serviceComponent, buildNamespace, orderByComparator, true);
536
537 array[1] = serviceComponent;
538
539 array[2] = getByBuildNamespace_PrevAndNext(session,
540 serviceComponent, buildNamespace, orderByComparator, false);
541
542 return array;
543 }
544 catch (Exception e) {
545 throw processException(e);
546 }
547 finally {
548 closeSession(session);
549 }
550 }
551
552 protected ServiceComponent getByBuildNamespace_PrevAndNext(
553 Session session, ServiceComponent serviceComponent,
554 String buildNamespace, OrderByComparator orderByComparator,
555 boolean previous) {
556 StringBundler query = null;
557
558 if (orderByComparator != null) {
559 query = new StringBundler(6 +
560 (orderByComparator.getOrderByFields().length * 6));
561 }
562 else {
563 query = new StringBundler(3);
564 }
565
566 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
567
568 if (buildNamespace == null) {
569 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
570 }
571 else {
572 if (buildNamespace.equals(StringPool.BLANK)) {
573 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
574 }
575 else {
576 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
577 }
578 }
579
580 if (orderByComparator != null) {
581 String[] orderByFields = orderByComparator.getOrderByFields();
582
583 if (orderByFields.length > 0) {
584 query.append(WHERE_AND);
585 }
586
587 for (int i = 0; i < orderByFields.length; i++) {
588 query.append(_ORDER_BY_ENTITY_ALIAS);
589 query.append(orderByFields[i]);
590
591 if ((i + 1) < orderByFields.length) {
592 if (orderByComparator.isAscending() ^ previous) {
593 query.append(WHERE_GREATER_THAN_HAS_NEXT);
594 }
595 else {
596 query.append(WHERE_LESSER_THAN_HAS_NEXT);
597 }
598 }
599 else {
600 if (orderByComparator.isAscending() ^ previous) {
601 query.append(WHERE_GREATER_THAN);
602 }
603 else {
604 query.append(WHERE_LESSER_THAN);
605 }
606 }
607 }
608
609 query.append(ORDER_BY_CLAUSE);
610
611 for (int i = 0; i < orderByFields.length; i++) {
612 query.append(_ORDER_BY_ENTITY_ALIAS);
613 query.append(orderByFields[i]);
614
615 if ((i + 1) < orderByFields.length) {
616 if (orderByComparator.isAscending() ^ previous) {
617 query.append(ORDER_BY_ASC_HAS_NEXT);
618 }
619 else {
620 query.append(ORDER_BY_DESC_HAS_NEXT);
621 }
622 }
623 else {
624 if (orderByComparator.isAscending() ^ previous) {
625 query.append(ORDER_BY_ASC);
626 }
627 else {
628 query.append(ORDER_BY_DESC);
629 }
630 }
631 }
632 }
633
634 else {
635 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
636 }
637
638 String sql = query.toString();
639
640 Query q = session.createQuery(sql);
641
642 q.setFirstResult(0);
643 q.setMaxResults(2);
644
645 QueryPos qPos = QueryPos.getInstance(q);
646
647 if (buildNamespace != null) {
648 qPos.add(buildNamespace);
649 }
650
651 if (orderByComparator != null) {
652 Object[] values = orderByComparator.getOrderByValues(serviceComponent);
653
654 for (Object value : values) {
655 qPos.add(value);
656 }
657 }
658
659 List<ServiceComponent> list = q.list();
660
661 if (list.size() == 2) {
662 return list.get(1);
663 }
664 else {
665 return null;
666 }
667 }
668
669 public ServiceComponent findByBNS_BNU(String buildNamespace,
670 long buildNumber)
671 throws NoSuchServiceComponentException, SystemException {
672 ServiceComponent serviceComponent = fetchByBNS_BNU(buildNamespace,
673 buildNumber);
674
675 if (serviceComponent == null) {
676 StringBundler msg = new StringBundler(6);
677
678 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
679
680 msg.append("buildNamespace=");
681 msg.append(buildNamespace);
682
683 msg.append(", buildNumber=");
684 msg.append(buildNumber);
685
686 msg.append(StringPool.CLOSE_CURLY_BRACE);
687
688 if (_log.isWarnEnabled()) {
689 _log.warn(msg.toString());
690 }
691
692 throw new NoSuchServiceComponentException(msg.toString());
693 }
694
695 return serviceComponent;
696 }
697
698 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
699 long buildNumber) throws SystemException {
700 return fetchByBNS_BNU(buildNamespace, buildNumber, true);
701 }
702
703 public ServiceComponent fetchByBNS_BNU(String buildNamespace,
704 long buildNumber, boolean retrieveFromCache) throws SystemException {
705 Object[] finderArgs = new Object[] { buildNamespace, new Long(buildNumber) };
706
707 Object result = null;
708
709 if (retrieveFromCache) {
710 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_BNS_BNU,
711 finderArgs, this);
712 }
713
714 if (result == null) {
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 StringBundler query = new StringBundler(4);
721
722 query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
723
724 if (buildNamespace == null) {
725 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
726 }
727 else {
728 if (buildNamespace.equals(StringPool.BLANK)) {
729 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
730 }
731 else {
732 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
733 }
734 }
735
736 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
737
738 query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
739
740 String sql = query.toString();
741
742 Query q = session.createQuery(sql);
743
744 QueryPos qPos = QueryPos.getInstance(q);
745
746 if (buildNamespace != null) {
747 qPos.add(buildNamespace);
748 }
749
750 qPos.add(buildNumber);
751
752 List<ServiceComponent> list = q.list();
753
754 result = list;
755
756 ServiceComponent serviceComponent = null;
757
758 if (list.isEmpty()) {
759 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
760 finderArgs, list);
761 }
762 else {
763 serviceComponent = list.get(0);
764
765 cacheResult(serviceComponent);
766
767 if ((serviceComponent.getBuildNamespace() == null) ||
768 !serviceComponent.getBuildNamespace()
769 .equals(buildNamespace) ||
770 (serviceComponent.getBuildNumber() != buildNumber)) {
771 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
772 finderArgs, serviceComponent);
773 }
774 }
775
776 return serviceComponent;
777 }
778 catch (Exception e) {
779 throw processException(e);
780 }
781 finally {
782 if (result == null) {
783 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
784 finderArgs, new ArrayList<ServiceComponent>());
785 }
786
787 closeSession(session);
788 }
789 }
790 else {
791 if (result instanceof List<?>) {
792 return null;
793 }
794 else {
795 return (ServiceComponent)result;
796 }
797 }
798 }
799
800 public List<ServiceComponent> findAll() throws SystemException {
801 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
802 }
803
804 public List<ServiceComponent> findAll(int start, int end)
805 throws SystemException {
806 return findAll(start, end, null);
807 }
808
809 public List<ServiceComponent> findAll(int start, int end,
810 OrderByComparator orderByComparator) throws SystemException {
811 Object[] finderArgs = new Object[] {
812 String.valueOf(start), String.valueOf(end),
813 String.valueOf(orderByComparator)
814 };
815
816 List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
817 finderArgs, this);
818
819 if (list == null) {
820 Session session = null;
821
822 try {
823 session = openSession();
824
825 StringBundler query = null;
826 String sql = null;
827
828 if (orderByComparator != null) {
829 query = new StringBundler(2 +
830 (orderByComparator.getOrderByFields().length * 3));
831
832 query.append(_SQL_SELECT_SERVICECOMPONENT);
833
834 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
835 orderByComparator);
836
837 sql = query.toString();
838 }
839
840 else {
841 sql = _SQL_SELECT_SERVICECOMPONENT.concat(ServiceComponentModelImpl.ORDER_BY_JPQL);
842 }
843
844 Query q = session.createQuery(sql);
845
846 if (orderByComparator == null) {
847 list = (List<ServiceComponent>)QueryUtil.list(q,
848 getDialect(), start, end, false);
849
850 Collections.sort(list);
851 }
852 else {
853 list = (List<ServiceComponent>)QueryUtil.list(q,
854 getDialect(), start, end);
855 }
856 }
857 catch (Exception e) {
858 throw processException(e);
859 }
860 finally {
861 if (list == null) {
862 list = new ArrayList<ServiceComponent>();
863 }
864
865 cacheResult(list);
866
867 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
868
869 closeSession(session);
870 }
871 }
872
873 return list;
874 }
875
876 public void removeByBuildNamespace(String buildNamespace)
877 throws SystemException {
878 for (ServiceComponent serviceComponent : findByBuildNamespace(
879 buildNamespace)) {
880 remove(serviceComponent);
881 }
882 }
883
884 public void removeByBNS_BNU(String buildNamespace, long buildNumber)
885 throws NoSuchServiceComponentException, SystemException {
886 ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
887 buildNumber);
888
889 remove(serviceComponent);
890 }
891
892 public void removeAll() throws SystemException {
893 for (ServiceComponent serviceComponent : findAll()) {
894 remove(serviceComponent);
895 }
896 }
897
898 public int countByBuildNamespace(String buildNamespace)
899 throws SystemException {
900 Object[] finderArgs = new Object[] { buildNamespace };
901
902 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
903 finderArgs, this);
904
905 if (count == null) {
906 Session session = null;
907
908 try {
909 session = openSession();
910
911 StringBundler query = new StringBundler(2);
912
913 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
914
915 if (buildNamespace == null) {
916 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
917 }
918 else {
919 if (buildNamespace.equals(StringPool.BLANK)) {
920 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
921 }
922 else {
923 query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
924 }
925 }
926
927 String sql = query.toString();
928
929 Query q = session.createQuery(sql);
930
931 QueryPos qPos = QueryPos.getInstance(q);
932
933 if (buildNamespace != null) {
934 qPos.add(buildNamespace);
935 }
936
937 count = (Long)q.uniqueResult();
938 }
939 catch (Exception e) {
940 throw processException(e);
941 }
942 finally {
943 if (count == null) {
944 count = Long.valueOf(0);
945 }
946
947 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
948 finderArgs, count);
949
950 closeSession(session);
951 }
952 }
953
954 return count.intValue();
955 }
956
957 public int countByBNS_BNU(String buildNamespace, long buildNumber)
958 throws SystemException {
959 Object[] finderArgs = new Object[] { buildNamespace, new Long(buildNumber) };
960
961 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BNS_BNU,
962 finderArgs, this);
963
964 if (count == null) {
965 Session session = null;
966
967 try {
968 session = openSession();
969
970 StringBundler query = new StringBundler(3);
971
972 query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
973
974 if (buildNamespace == null) {
975 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
976 }
977 else {
978 if (buildNamespace.equals(StringPool.BLANK)) {
979 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
980 }
981 else {
982 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
983 }
984 }
985
986 query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
987
988 String sql = query.toString();
989
990 Query q = session.createQuery(sql);
991
992 QueryPos qPos = QueryPos.getInstance(q);
993
994 if (buildNamespace != null) {
995 qPos.add(buildNamespace);
996 }
997
998 qPos.add(buildNumber);
999
1000 count = (Long)q.uniqueResult();
1001 }
1002 catch (Exception e) {
1003 throw processException(e);
1004 }
1005 finally {
1006 if (count == null) {
1007 count = Long.valueOf(0);
1008 }
1009
1010 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU,
1011 finderArgs, count);
1012
1013 closeSession(session);
1014 }
1015 }
1016
1017 return count.intValue();
1018 }
1019
1020 public int countAll() throws SystemException {
1021 Object[] finderArgs = new Object[0];
1022
1023 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1024 finderArgs, this);
1025
1026 if (count == null) {
1027 Session session = null;
1028
1029 try {
1030 session = openSession();
1031
1032 Query q = session.createQuery(_SQL_COUNT_SERVICECOMPONENT);
1033
1034 count = (Long)q.uniqueResult();
1035 }
1036 catch (Exception e) {
1037 throw processException(e);
1038 }
1039 finally {
1040 if (count == null) {
1041 count = Long.valueOf(0);
1042 }
1043
1044 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1045 count);
1046
1047 closeSession(session);
1048 }
1049 }
1050
1051 return count.intValue();
1052 }
1053
1054 public void afterPropertiesSet() {
1055 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1056 com.liferay.portal.util.PropsUtil.get(
1057 "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1058
1059 if (listenerClassNames.length > 0) {
1060 try {
1061 List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1062
1063 for (String listenerClassName : listenerClassNames) {
1064 listenersList.add((ModelListener<ServiceComponent>)InstanceFactory.newInstance(
1065 listenerClassName));
1066 }
1067
1068 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1069 }
1070 catch (Exception e) {
1071 _log.error(e);
1072 }
1073 }
1074 }
1075
1076 @BeanReference(type = AccountPersistence.class)
1077 protected AccountPersistence accountPersistence;
1078 @BeanReference(type = AddressPersistence.class)
1079 protected AddressPersistence addressPersistence;
1080 @BeanReference(type = BrowserTrackerPersistence.class)
1081 protected BrowserTrackerPersistence browserTrackerPersistence;
1082 @BeanReference(type = ClassNamePersistence.class)
1083 protected ClassNamePersistence classNamePersistence;
1084 @BeanReference(type = CompanyPersistence.class)
1085 protected CompanyPersistence companyPersistence;
1086 @BeanReference(type = ContactPersistence.class)
1087 protected ContactPersistence contactPersistence;
1088 @BeanReference(type = CountryPersistence.class)
1089 protected CountryPersistence countryPersistence;
1090 @BeanReference(type = EmailAddressPersistence.class)
1091 protected EmailAddressPersistence emailAddressPersistence;
1092 @BeanReference(type = GroupPersistence.class)
1093 protected GroupPersistence groupPersistence;
1094 @BeanReference(type = ImagePersistence.class)
1095 protected ImagePersistence imagePersistence;
1096 @BeanReference(type = LayoutPersistence.class)
1097 protected LayoutPersistence layoutPersistence;
1098 @BeanReference(type = LayoutPrototypePersistence.class)
1099 protected LayoutPrototypePersistence layoutPrototypePersistence;
1100 @BeanReference(type = LayoutSetPersistence.class)
1101 protected LayoutSetPersistence layoutSetPersistence;
1102 @BeanReference(type = LayoutSetPrototypePersistence.class)
1103 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1104 @BeanReference(type = ListTypePersistence.class)
1105 protected ListTypePersistence listTypePersistence;
1106 @BeanReference(type = LockPersistence.class)
1107 protected LockPersistence lockPersistence;
1108 @BeanReference(type = MembershipRequestPersistence.class)
1109 protected MembershipRequestPersistence membershipRequestPersistence;
1110 @BeanReference(type = OrganizationPersistence.class)
1111 protected OrganizationPersistence organizationPersistence;
1112 @BeanReference(type = OrgGroupPermissionPersistence.class)
1113 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1114 @BeanReference(type = OrgGroupRolePersistence.class)
1115 protected OrgGroupRolePersistence orgGroupRolePersistence;
1116 @BeanReference(type = OrgLaborPersistence.class)
1117 protected OrgLaborPersistence orgLaborPersistence;
1118 @BeanReference(type = PasswordPolicyPersistence.class)
1119 protected PasswordPolicyPersistence passwordPolicyPersistence;
1120 @BeanReference(type = PasswordPolicyRelPersistence.class)
1121 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1122 @BeanReference(type = PasswordTrackerPersistence.class)
1123 protected PasswordTrackerPersistence passwordTrackerPersistence;
1124 @BeanReference(type = PermissionPersistence.class)
1125 protected PermissionPersistence permissionPersistence;
1126 @BeanReference(type = PhonePersistence.class)
1127 protected PhonePersistence phonePersistence;
1128 @BeanReference(type = PluginSettingPersistence.class)
1129 protected PluginSettingPersistence pluginSettingPersistence;
1130 @BeanReference(type = PortletPersistence.class)
1131 protected PortletPersistence portletPersistence;
1132 @BeanReference(type = PortletItemPersistence.class)
1133 protected PortletItemPersistence portletItemPersistence;
1134 @BeanReference(type = PortletPreferencesPersistence.class)
1135 protected PortletPreferencesPersistence portletPreferencesPersistence;
1136 @BeanReference(type = RegionPersistence.class)
1137 protected RegionPersistence regionPersistence;
1138 @BeanReference(type = ReleasePersistence.class)
1139 protected ReleasePersistence releasePersistence;
1140 @BeanReference(type = ResourcePersistence.class)
1141 protected ResourcePersistence resourcePersistence;
1142 @BeanReference(type = ResourceActionPersistence.class)
1143 protected ResourceActionPersistence resourceActionPersistence;
1144 @BeanReference(type = ResourceCodePersistence.class)
1145 protected ResourceCodePersistence resourceCodePersistence;
1146 @BeanReference(type = ResourcePermissionPersistence.class)
1147 protected ResourcePermissionPersistence resourcePermissionPersistence;
1148 @BeanReference(type = RolePersistence.class)
1149 protected RolePersistence rolePersistence;
1150 @BeanReference(type = ServiceComponentPersistence.class)
1151 protected ServiceComponentPersistence serviceComponentPersistence;
1152 @BeanReference(type = ShardPersistence.class)
1153 protected ShardPersistence shardPersistence;
1154 @BeanReference(type = SubscriptionPersistence.class)
1155 protected SubscriptionPersistence subscriptionPersistence;
1156 @BeanReference(type = TicketPersistence.class)
1157 protected TicketPersistence ticketPersistence;
1158 @BeanReference(type = TeamPersistence.class)
1159 protected TeamPersistence teamPersistence;
1160 @BeanReference(type = UserPersistence.class)
1161 protected UserPersistence userPersistence;
1162 @BeanReference(type = UserGroupPersistence.class)
1163 protected UserGroupPersistence userGroupPersistence;
1164 @BeanReference(type = UserGroupGroupRolePersistence.class)
1165 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1166 @BeanReference(type = UserGroupRolePersistence.class)
1167 protected UserGroupRolePersistence userGroupRolePersistence;
1168 @BeanReference(type = UserIdMapperPersistence.class)
1169 protected UserIdMapperPersistence userIdMapperPersistence;
1170 @BeanReference(type = UserTrackerPersistence.class)
1171 protected UserTrackerPersistence userTrackerPersistence;
1172 @BeanReference(type = UserTrackerPathPersistence.class)
1173 protected UserTrackerPathPersistence userTrackerPathPersistence;
1174 @BeanReference(type = WebDAVPropsPersistence.class)
1175 protected WebDAVPropsPersistence webDAVPropsPersistence;
1176 @BeanReference(type = WebsitePersistence.class)
1177 protected WebsitePersistence websitePersistence;
1178 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1179 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1180 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1181 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1182 private static final String _SQL_SELECT_SERVICECOMPONENT = "SELECT serviceComponent FROM ServiceComponent serviceComponent";
1183 private static final String _SQL_SELECT_SERVICECOMPONENT_WHERE = "SELECT serviceComponent FROM ServiceComponent serviceComponent WHERE ";
1184 private static final String _SQL_COUNT_SERVICECOMPONENT = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent";
1185 private static final String _SQL_COUNT_SERVICECOMPONENT_WHERE = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent WHERE ";
1186 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL";
1187 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ?";
1188 private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?)";
1189 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL AND ";
1190 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ? AND ";
1191 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?) AND ";
1192 private static final String _FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2 = "serviceComponent.buildNumber = ?";
1193 private static final String _ORDER_BY_ENTITY_ALIAS = "serviceComponent.";
1194 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ServiceComponent exists with the primary key ";
1195 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ServiceComponent exists with the key {";
1196 private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1197}