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