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