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