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