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