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