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