001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchServiceComponentException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.ServiceComponent;
040    import com.liferay.portal.model.impl.ServiceComponentImpl;
041    import com.liferay.portal.model.impl.ServiceComponentModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the service component service.
052     *
053     * <p>
054     * Never modify or reference this class directly. Always use {@link ServiceComponentUtil} to access the service component persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
055     * </p>
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see ServiceComponentPersistence
063     * @see ServiceComponentUtil
064     * @generated
065     */
066    public class ServiceComponentPersistenceImpl extends BasePersistenceImpl<ServiceComponent>
067            implements ServiceComponentPersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = ServiceComponentImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
072                            ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
073                            FINDER_CLASS_NAME_LIST, "findByBuildNamespace",
074                            new String[] {
075                                    String.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_BUILDNAMESPACE = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
081                            ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
082                            FINDER_CLASS_NAME_LIST, "countByBuildNamespace",
083                            new String[] { String.class.getName() });
084            public static final FinderPath FINDER_PATH_FETCH_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
085                            ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
086                            FINDER_CLASS_NAME_ENTITY, "fetchByBNS_BNU",
087                            new String[] { String.class.getName(), Long.class.getName() });
088            public static final FinderPath FINDER_PATH_COUNT_BY_BNS_BNU = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
089                            ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "countByBNS_BNU",
091                            new String[] { String.class.getName(), Long.class.getName() });
092            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
093                            ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
096                            ServiceComponentModelImpl.FINDER_CACHE_ENABLED,
097                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
098    
099            /**
100             * Caches the service component in the entity cache if it is enabled.
101             *
102             * @param serviceComponent the service component to cache
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            /**
117             * Caches the service components in the entity cache if it is enabled.
118             *
119             * @param serviceComponents the service components to cache
120             */
121            public void cacheResult(List<ServiceComponent> serviceComponents) {
122                    for (ServiceComponent serviceComponent : serviceComponents) {
123                            if (EntityCacheUtil.getResult(
124                                                    ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
125                                                    ServiceComponentImpl.class,
126                                                    serviceComponent.getPrimaryKey(), this) == null) {
127                                    cacheResult(serviceComponent);
128                            }
129                    }
130            }
131    
132            /**
133             * Clears the cache for all service components.
134             *
135             * <p>
136             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
137             * </p>
138             */
139            public void clearCache() {
140                    CacheRegistryUtil.clear(ServiceComponentImpl.class.getName());
141                    EntityCacheUtil.clearCache(ServiceComponentImpl.class.getName());
142                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
143                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
144            }
145    
146            /**
147             * Clears the cache for the service component.
148             *
149             * <p>
150             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
151             * </p>
152             */
153            public void clearCache(ServiceComponent serviceComponent) {
154                    EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
155                            ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
156    
157                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
158                            new Object[] {
159                                    serviceComponent.getBuildNamespace(),
160                                    new Long(serviceComponent.getBuildNumber())
161                            });
162            }
163    
164            /**
165             * Creates a new service component with the primary key. Does not add the service component to the database.
166             *
167             * @param serviceComponentId the primary key for the new service component
168             * @return the new service component
169             */
170            public ServiceComponent create(long serviceComponentId) {
171                    ServiceComponent serviceComponent = new ServiceComponentImpl();
172    
173                    serviceComponent.setNew(true);
174                    serviceComponent.setPrimaryKey(serviceComponentId);
175    
176                    return serviceComponent;
177            }
178    
179            /**
180             * Removes the service component with the primary key from the database. Also notifies the appropriate model listeners.
181             *
182             * @param primaryKey the primary key of the service component to remove
183             * @return the service component that was removed
184             * @throws com.liferay.portal.NoSuchModelException if a service component with the primary key could not be found
185             * @throws SystemException if a system exception occurred
186             */
187            public ServiceComponent remove(Serializable primaryKey)
188                    throws NoSuchModelException, SystemException {
189                    return remove(((Long)primaryKey).longValue());
190            }
191    
192            /**
193             * Removes the service component with the primary key from the database. Also notifies the appropriate model listeners.
194             *
195             * @param serviceComponentId the primary key of the service component to remove
196             * @return the service component that was removed
197             * @throws com.liferay.portal.NoSuchServiceComponentException if a service component with the primary key could not be found
198             * @throws SystemException if a system exception occurred
199             */
200            public ServiceComponent remove(long serviceComponentId)
201                    throws NoSuchServiceComponentException, SystemException {
202                    Session session = null;
203    
204                    try {
205                            session = openSession();
206    
207                            ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
208                                            new Long(serviceComponentId));
209    
210                            if (serviceComponent == null) {
211                                    if (_log.isWarnEnabled()) {
212                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
213                                                    serviceComponentId);
214                                    }
215    
216                                    throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
217                                            serviceComponentId);
218                            }
219    
220                            return remove(serviceComponent);
221                    }
222                    catch (NoSuchServiceComponentException nsee) {
223                            throw nsee;
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231            }
232    
233            protected ServiceComponent removeImpl(ServiceComponent serviceComponent)
234                    throws SystemException {
235                    serviceComponent = toUnwrappedModel(serviceComponent);
236    
237                    Session session = null;
238    
239                    try {
240                            session = openSession();
241    
242                            if (serviceComponent.isCachedModel() ||
243                                            BatchSessionUtil.isEnabled()) {
244                                    Object staleObject = session.get(ServiceComponentImpl.class,
245                                                    serviceComponent.getPrimaryKeyObj());
246    
247                                    if (staleObject != null) {
248                                            session.evict(staleObject);
249                                    }
250                            }
251    
252                            session.delete(serviceComponent);
253    
254                            session.flush();
255                    }
256                    catch (Exception e) {
257                            throw processException(e);
258                    }
259                    finally {
260                            closeSession(session);
261                    }
262    
263                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
264    
265                    ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
266    
267                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
268                            new Object[] {
269                                    serviceComponentModelImpl.getOriginalBuildNamespace(),
270                                    new Long(serviceComponentModelImpl.getOriginalBuildNumber())
271                            });
272    
273                    EntityCacheUtil.removeResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
274                            ServiceComponentImpl.class, serviceComponent.getPrimaryKey());
275    
276                    return serviceComponent;
277            }
278    
279            public ServiceComponent updateImpl(
280                    com.liferay.portal.model.ServiceComponent serviceComponent,
281                    boolean merge) throws SystemException {
282                    serviceComponent = toUnwrappedModel(serviceComponent);
283    
284                    boolean isNew = serviceComponent.isNew();
285    
286                    ServiceComponentModelImpl serviceComponentModelImpl = (ServiceComponentModelImpl)serviceComponent;
287    
288                    Session session = null;
289    
290                    try {
291                            session = openSession();
292    
293                            BatchSessionUtil.update(session, serviceComponent, merge);
294    
295                            serviceComponent.setNew(false);
296                    }
297                    catch (Exception e) {
298                            throw processException(e);
299                    }
300                    finally {
301                            closeSession(session);
302                    }
303    
304                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
305    
306                    EntityCacheUtil.putResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
307                            ServiceComponentImpl.class, serviceComponent.getPrimaryKey(),
308                            serviceComponent);
309    
310                    if (!isNew &&
311                                    (!Validator.equals(serviceComponent.getBuildNamespace(),
312                                            serviceComponentModelImpl.getOriginalBuildNamespace()) ||
313                                    (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
314                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_BNS_BNU,
315                                    new Object[] {
316                                            serviceComponentModelImpl.getOriginalBuildNamespace(),
317                                            new Long(serviceComponentModelImpl.getOriginalBuildNumber())
318                                    });
319                    }
320    
321                    if (isNew ||
322                                    (!Validator.equals(serviceComponent.getBuildNamespace(),
323                                            serviceComponentModelImpl.getOriginalBuildNamespace()) ||
324                                    (serviceComponent.getBuildNumber() != serviceComponentModelImpl.getOriginalBuildNumber()))) {
325                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
326                                    new Object[] {
327                                            serviceComponent.getBuildNamespace(),
328                                            new Long(serviceComponent.getBuildNumber())
329                                    }, serviceComponent);
330                    }
331    
332                    return serviceComponent;
333            }
334    
335            protected ServiceComponent toUnwrappedModel(
336                    ServiceComponent serviceComponent) {
337                    if (serviceComponent instanceof ServiceComponentImpl) {
338                            return serviceComponent;
339                    }
340    
341                    ServiceComponentImpl serviceComponentImpl = new ServiceComponentImpl();
342    
343                    serviceComponentImpl.setNew(serviceComponent.isNew());
344                    serviceComponentImpl.setPrimaryKey(serviceComponent.getPrimaryKey());
345    
346                    serviceComponentImpl.setServiceComponentId(serviceComponent.getServiceComponentId());
347                    serviceComponentImpl.setBuildNamespace(serviceComponent.getBuildNamespace());
348                    serviceComponentImpl.setBuildNumber(serviceComponent.getBuildNumber());
349                    serviceComponentImpl.setBuildDate(serviceComponent.getBuildDate());
350                    serviceComponentImpl.setData(serviceComponent.getData());
351    
352                    return serviceComponentImpl;
353            }
354    
355            /**
356             * Finds the service component with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
357             *
358             * @param primaryKey the primary key of the service component to find
359             * @return the service component
360             * @throws com.liferay.portal.NoSuchModelException if a service component with the primary key could not be found
361             * @throws SystemException if a system exception occurred
362             */
363            public ServiceComponent findByPrimaryKey(Serializable primaryKey)
364                    throws NoSuchModelException, SystemException {
365                    return findByPrimaryKey(((Long)primaryKey).longValue());
366            }
367    
368            /**
369             * Finds the service component with the primary key or throws a {@link com.liferay.portal.NoSuchServiceComponentException} if it could not be found.
370             *
371             * @param serviceComponentId the primary key of the service component to find
372             * @return the service component
373             * @throws com.liferay.portal.NoSuchServiceComponentException if a service component with the primary key could not be found
374             * @throws SystemException if a system exception occurred
375             */
376            public ServiceComponent findByPrimaryKey(long serviceComponentId)
377                    throws NoSuchServiceComponentException, SystemException {
378                    ServiceComponent serviceComponent = fetchByPrimaryKey(serviceComponentId);
379    
380                    if (serviceComponent == null) {
381                            if (_log.isWarnEnabled()) {
382                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383                                            serviceComponentId);
384                            }
385    
386                            throw new NoSuchServiceComponentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
387                                    serviceComponentId);
388                    }
389    
390                    return serviceComponent;
391            }
392    
393            /**
394             * Finds the service component with the primary key or returns <code>null</code> if it could not be found.
395             *
396             * @param primaryKey the primary key of the service component to find
397             * @return the service component, or <code>null</code> if a service component with the primary key could not be found
398             * @throws SystemException if a system exception occurred
399             */
400            public ServiceComponent fetchByPrimaryKey(Serializable primaryKey)
401                    throws SystemException {
402                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
403            }
404    
405            /**
406             * Finds the service component with the primary key or returns <code>null</code> if it could not be found.
407             *
408             * @param serviceComponentId the primary key of the service component to find
409             * @return the service component, or <code>null</code> if a service component with the primary key could not be found
410             * @throws SystemException if a system exception occurred
411             */
412            public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
413                    throws SystemException {
414                    ServiceComponent serviceComponent = (ServiceComponent)EntityCacheUtil.getResult(ServiceComponentModelImpl.ENTITY_CACHE_ENABLED,
415                                    ServiceComponentImpl.class, serviceComponentId, this);
416    
417                    if (serviceComponent == null) {
418                            Session session = null;
419    
420                            try {
421                                    session = openSession();
422    
423                                    serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
424                                                    new Long(serviceComponentId));
425                            }
426                            catch (Exception e) {
427                                    throw processException(e);
428                            }
429                            finally {
430                                    if (serviceComponent != null) {
431                                            cacheResult(serviceComponent);
432                                    }
433    
434                                    closeSession(session);
435                            }
436                    }
437    
438                    return serviceComponent;
439            }
440    
441            /**
442             * Finds all the service components where buildNamespace = &#63;.
443             *
444             * @param buildNamespace the build namespace to search with
445             * @return the matching service components
446             * @throws SystemException if a system exception occurred
447             */
448            public List<ServiceComponent> findByBuildNamespace(String buildNamespace)
449                    throws SystemException {
450                    return findByBuildNamespace(buildNamespace, QueryUtil.ALL_POS,
451                            QueryUtil.ALL_POS, null);
452            }
453    
454            /**
455             * Finds a range of all the service components where buildNamespace = &#63;.
456             *
457             * <p>
458             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
459             * </p>
460             *
461             * @param buildNamespace the build namespace to search with
462             * @param start the lower bound of the range of service components to return
463             * @param end the upper bound of the range of service components to return (not inclusive)
464             * @return the range of matching service components
465             * @throws SystemException if a system exception occurred
466             */
467            public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
468                    int start, int end) throws SystemException {
469                    return findByBuildNamespace(buildNamespace, start, end, null);
470            }
471    
472            /**
473             * Finds an ordered range of all the service components where buildNamespace = &#63;.
474             *
475             * <p>
476             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
477             * </p>
478             *
479             * @param buildNamespace the build namespace to search with
480             * @param start the lower bound of the range of service components to return
481             * @param end the upper bound of the range of service components to return (not inclusive)
482             * @param orderByComparator the comparator to order the results by
483             * @return the ordered range of matching service components
484             * @throws SystemException if a system exception occurred
485             */
486            public List<ServiceComponent> findByBuildNamespace(String buildNamespace,
487                    int start, int end, OrderByComparator orderByComparator)
488                    throws SystemException {
489                    Object[] finderArgs = new Object[] {
490                                    buildNamespace,
491                                    
492                                    String.valueOf(start), String.valueOf(end),
493                                    String.valueOf(orderByComparator)
494                            };
495    
496                    List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
497                                    finderArgs, this);
498    
499                    if (list == null) {
500                            Session session = null;
501    
502                            try {
503                                    session = openSession();
504    
505                                    StringBundler query = null;
506    
507                                    if (orderByComparator != null) {
508                                            query = new StringBundler(3 +
509                                                            (orderByComparator.getOrderByFields().length * 3));
510                                    }
511                                    else {
512                                            query = new StringBundler(3);
513                                    }
514    
515                                    query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
516    
517                                    if (buildNamespace == null) {
518                                            query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
519                                    }
520                                    else {
521                                            if (buildNamespace.equals(StringPool.BLANK)) {
522                                                    query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
523                                            }
524                                            else {
525                                                    query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
526                                            }
527                                    }
528    
529                                    if (orderByComparator != null) {
530                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
531                                                    orderByComparator);
532                                    }
533    
534                                    else {
535                                            query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
536                                    }
537    
538                                    String sql = query.toString();
539    
540                                    Query q = session.createQuery(sql);
541    
542                                    QueryPos qPos = QueryPos.getInstance(q);
543    
544                                    if (buildNamespace != null) {
545                                            qPos.add(buildNamespace);
546                                    }
547    
548                                    list = (List<ServiceComponent>)QueryUtil.list(q, getDialect(),
549                                                    start, end);
550                            }
551                            catch (Exception e) {
552                                    throw processException(e);
553                            }
554                            finally {
555                                    if (list == null) {
556                                            list = new ArrayList<ServiceComponent>();
557                                    }
558    
559                                    cacheResult(list);
560    
561                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_BUILDNAMESPACE,
562                                            finderArgs, list);
563    
564                                    closeSession(session);
565                            }
566                    }
567    
568                    return list;
569            }
570    
571            /**
572             * Finds the first service component in the ordered set where buildNamespace = &#63;.
573             *
574             * <p>
575             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
576             * </p>
577             *
578             * @param buildNamespace the build namespace to search with
579             * @param orderByComparator the comparator to order the set by
580             * @return the first matching service component
581             * @throws com.liferay.portal.NoSuchServiceComponentException if a matching service component could not be found
582             * @throws SystemException if a system exception occurred
583             */
584            public ServiceComponent findByBuildNamespace_First(String buildNamespace,
585                    OrderByComparator orderByComparator)
586                    throws NoSuchServiceComponentException, SystemException {
587                    List<ServiceComponent> list = findByBuildNamespace(buildNamespace, 0,
588                                    1, orderByComparator);
589    
590                    if (list.isEmpty()) {
591                            StringBundler msg = new StringBundler(4);
592    
593                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594    
595                            msg.append("buildNamespace=");
596                            msg.append(buildNamespace);
597    
598                            msg.append(StringPool.CLOSE_CURLY_BRACE);
599    
600                            throw new NoSuchServiceComponentException(msg.toString());
601                    }
602                    else {
603                            return list.get(0);
604                    }
605            }
606    
607            /**
608             * Finds the last service component in the ordered set where buildNamespace = &#63;.
609             *
610             * <p>
611             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
612             * </p>
613             *
614             * @param buildNamespace the build namespace to search with
615             * @param orderByComparator the comparator to order the set by
616             * @return the last matching service component
617             * @throws com.liferay.portal.NoSuchServiceComponentException if a matching service component could not be found
618             * @throws SystemException if a system exception occurred
619             */
620            public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
621                    OrderByComparator orderByComparator)
622                    throws NoSuchServiceComponentException, SystemException {
623                    int count = countByBuildNamespace(buildNamespace);
624    
625                    List<ServiceComponent> list = findByBuildNamespace(buildNamespace,
626                                    count - 1, count, orderByComparator);
627    
628                    if (list.isEmpty()) {
629                            StringBundler msg = new StringBundler(4);
630    
631                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
632    
633                            msg.append("buildNamespace=");
634                            msg.append(buildNamespace);
635    
636                            msg.append(StringPool.CLOSE_CURLY_BRACE);
637    
638                            throw new NoSuchServiceComponentException(msg.toString());
639                    }
640                    else {
641                            return list.get(0);
642                    }
643            }
644    
645            /**
646             * Finds the service components before and after the current service component in the ordered set where buildNamespace = &#63;.
647             *
648             * <p>
649             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
650             * </p>
651             *
652             * @param serviceComponentId the primary key of the current service component
653             * @param buildNamespace the build namespace to search with
654             * @param orderByComparator the comparator to order the set by
655             * @return the previous, current, and next service component
656             * @throws com.liferay.portal.NoSuchServiceComponentException if a service component with the primary key could not be found
657             * @throws SystemException if a system exception occurred
658             */
659            public ServiceComponent[] findByBuildNamespace_PrevAndNext(
660                    long serviceComponentId, String buildNamespace,
661                    OrderByComparator orderByComparator)
662                    throws NoSuchServiceComponentException, SystemException {
663                    ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
664    
665                    Session session = null;
666    
667                    try {
668                            session = openSession();
669    
670                            ServiceComponent[] array = new ServiceComponentImpl[3];
671    
672                            array[0] = getByBuildNamespace_PrevAndNext(session,
673                                            serviceComponent, buildNamespace, orderByComparator, true);
674    
675                            array[1] = serviceComponent;
676    
677                            array[2] = getByBuildNamespace_PrevAndNext(session,
678                                            serviceComponent, buildNamespace, orderByComparator, false);
679    
680                            return array;
681                    }
682                    catch (Exception e) {
683                            throw processException(e);
684                    }
685                    finally {
686                            closeSession(session);
687                    }
688            }
689    
690            protected ServiceComponent getByBuildNamespace_PrevAndNext(
691                    Session session, ServiceComponent serviceComponent,
692                    String buildNamespace, OrderByComparator orderByComparator,
693                    boolean previous) {
694                    StringBundler query = null;
695    
696                    if (orderByComparator != null) {
697                            query = new StringBundler(6 +
698                                            (orderByComparator.getOrderByFields().length * 6));
699                    }
700                    else {
701                            query = new StringBundler(3);
702                    }
703    
704                    query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
705    
706                    if (buildNamespace == null) {
707                            query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
708                    }
709                    else {
710                            if (buildNamespace.equals(StringPool.BLANK)) {
711                                    query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
712                            }
713                            else {
714                                    query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
715                            }
716                    }
717    
718                    if (orderByComparator != null) {
719                            String[] orderByFields = orderByComparator.getOrderByFields();
720    
721                            if (orderByFields.length > 0) {
722                                    query.append(WHERE_AND);
723                            }
724    
725                            for (int i = 0; i < orderByFields.length; i++) {
726                                    query.append(_ORDER_BY_ENTITY_ALIAS);
727                                    query.append(orderByFields[i]);
728    
729                                    if ((i + 1) < orderByFields.length) {
730                                            if (orderByComparator.isAscending() ^ previous) {
731                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
732                                            }
733                                            else {
734                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
735                                            }
736                                    }
737                                    else {
738                                            if (orderByComparator.isAscending() ^ previous) {
739                                                    query.append(WHERE_GREATER_THAN);
740                                            }
741                                            else {
742                                                    query.append(WHERE_LESSER_THAN);
743                                            }
744                                    }
745                            }
746    
747                            query.append(ORDER_BY_CLAUSE);
748    
749                            for (int i = 0; i < orderByFields.length; i++) {
750                                    query.append(_ORDER_BY_ENTITY_ALIAS);
751                                    query.append(orderByFields[i]);
752    
753                                    if ((i + 1) < orderByFields.length) {
754                                            if (orderByComparator.isAscending() ^ previous) {
755                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
756                                            }
757                                            else {
758                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
759                                            }
760                                    }
761                                    else {
762                                            if (orderByComparator.isAscending() ^ previous) {
763                                                    query.append(ORDER_BY_ASC);
764                                            }
765                                            else {
766                                                    query.append(ORDER_BY_DESC);
767                                            }
768                                    }
769                            }
770                    }
771    
772                    else {
773                            query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
774                    }
775    
776                    String sql = query.toString();
777    
778                    Query q = session.createQuery(sql);
779    
780                    q.setFirstResult(0);
781                    q.setMaxResults(2);
782    
783                    QueryPos qPos = QueryPos.getInstance(q);
784    
785                    if (buildNamespace != null) {
786                            qPos.add(buildNamespace);
787                    }
788    
789                    if (orderByComparator != null) {
790                            Object[] values = orderByComparator.getOrderByValues(serviceComponent);
791    
792                            for (Object value : values) {
793                                    qPos.add(value);
794                            }
795                    }
796    
797                    List<ServiceComponent> list = q.list();
798    
799                    if (list.size() == 2) {
800                            return list.get(1);
801                    }
802                    else {
803                            return null;
804                    }
805            }
806    
807            /**
808             * Finds the service component where buildNamespace = &#63; and buildNumber = &#63; or throws a {@link com.liferay.portal.NoSuchServiceComponentException} if it could not be found.
809             *
810             * @param buildNamespace the build namespace to search with
811             * @param buildNumber the build number to search with
812             * @return the matching service component
813             * @throws com.liferay.portal.NoSuchServiceComponentException if a matching service component could not be found
814             * @throws SystemException if a system exception occurred
815             */
816            public ServiceComponent findByBNS_BNU(String buildNamespace,
817                    long buildNumber)
818                    throws NoSuchServiceComponentException, SystemException {
819                    ServiceComponent serviceComponent = fetchByBNS_BNU(buildNamespace,
820                                    buildNumber);
821    
822                    if (serviceComponent == null) {
823                            StringBundler msg = new StringBundler(6);
824    
825                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826    
827                            msg.append("buildNamespace=");
828                            msg.append(buildNamespace);
829    
830                            msg.append(", buildNumber=");
831                            msg.append(buildNumber);
832    
833                            msg.append(StringPool.CLOSE_CURLY_BRACE);
834    
835                            if (_log.isWarnEnabled()) {
836                                    _log.warn(msg.toString());
837                            }
838    
839                            throw new NoSuchServiceComponentException(msg.toString());
840                    }
841    
842                    return serviceComponent;
843            }
844    
845            /**
846             * Finds the service component where buildNamespace = &#63; and buildNumber = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
847             *
848             * @param buildNamespace the build namespace to search with
849             * @param buildNumber the build number to search with
850             * @return the matching service component, or <code>null</code> if a matching service component could not be found
851             * @throws SystemException if a system exception occurred
852             */
853            public ServiceComponent fetchByBNS_BNU(String buildNamespace,
854                    long buildNumber) throws SystemException {
855                    return fetchByBNS_BNU(buildNamespace, buildNumber, true);
856            }
857    
858            /**
859             * Finds the service component where buildNamespace = &#63; and buildNumber = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
860             *
861             * @param buildNamespace the build namespace to search with
862             * @param buildNumber the build number to search with
863             * @return the matching service component, or <code>null</code> if a matching service component could not be found
864             * @throws SystemException if a system exception occurred
865             */
866            public ServiceComponent fetchByBNS_BNU(String buildNamespace,
867                    long buildNumber, boolean retrieveFromCache) throws SystemException {
868                    Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
869    
870                    Object result = null;
871    
872                    if (retrieveFromCache) {
873                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_BNS_BNU,
874                                            finderArgs, this);
875                    }
876    
877                    if (result == null) {
878                            Session session = null;
879    
880                            try {
881                                    session = openSession();
882    
883                                    StringBundler query = new StringBundler(4);
884    
885                                    query.append(_SQL_SELECT_SERVICECOMPONENT_WHERE);
886    
887                                    if (buildNamespace == null) {
888                                            query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
889                                    }
890                                    else {
891                                            if (buildNamespace.equals(StringPool.BLANK)) {
892                                                    query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
893                                            }
894                                            else {
895                                                    query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
896                                            }
897                                    }
898    
899                                    query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
900    
901                                    query.append(ServiceComponentModelImpl.ORDER_BY_JPQL);
902    
903                                    String sql = query.toString();
904    
905                                    Query q = session.createQuery(sql);
906    
907                                    QueryPos qPos = QueryPos.getInstance(q);
908    
909                                    if (buildNamespace != null) {
910                                            qPos.add(buildNamespace);
911                                    }
912    
913                                    qPos.add(buildNumber);
914    
915                                    List<ServiceComponent> list = q.list();
916    
917                                    result = list;
918    
919                                    ServiceComponent serviceComponent = null;
920    
921                                    if (list.isEmpty()) {
922                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
923                                                    finderArgs, list);
924                                    }
925                                    else {
926                                            serviceComponent = list.get(0);
927    
928                                            cacheResult(serviceComponent);
929    
930                                            if ((serviceComponent.getBuildNamespace() == null) ||
931                                                            !serviceComponent.getBuildNamespace()
932                                                                                                     .equals(buildNamespace) ||
933                                                            (serviceComponent.getBuildNumber() != buildNumber)) {
934                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
935                                                            finderArgs, serviceComponent);
936                                            }
937                                    }
938    
939                                    return serviceComponent;
940                            }
941                            catch (Exception e) {
942                                    throw processException(e);
943                            }
944                            finally {
945                                    if (result == null) {
946                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_BNS_BNU,
947                                                    finderArgs, new ArrayList<ServiceComponent>());
948                                    }
949    
950                                    closeSession(session);
951                            }
952                    }
953                    else {
954                            if (result instanceof List<?>) {
955                                    return null;
956                            }
957                            else {
958                                    return (ServiceComponent)result;
959                            }
960                    }
961            }
962    
963            /**
964             * Finds all the service components.
965             *
966             * @return the service components
967             * @throws SystemException if a system exception occurred
968             */
969            public List<ServiceComponent> findAll() throws SystemException {
970                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
971            }
972    
973            /**
974             * Finds a range of all the service components.
975             *
976             * <p>
977             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
978             * </p>
979             *
980             * @param start the lower bound of the range of service components to return
981             * @param end the upper bound of the range of service components to return (not inclusive)
982             * @return the range of service components
983             * @throws SystemException if a system exception occurred
984             */
985            public List<ServiceComponent> findAll(int start, int end)
986                    throws SystemException {
987                    return findAll(start, end, null);
988            }
989    
990            /**
991             * Finds an ordered range of all the service components.
992             *
993             * <p>
994             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
995             * </p>
996             *
997             * @param start the lower bound of the range of service components to return
998             * @param end the upper bound of the range of service components to return (not inclusive)
999             * @param orderByComparator the comparator to order the results by
1000             * @return the ordered range of service components
1001             * @throws SystemException if a system exception occurred
1002             */
1003            public List<ServiceComponent> findAll(int start, int end,
1004                    OrderByComparator orderByComparator) throws SystemException {
1005                    Object[] finderArgs = new Object[] {
1006                                    String.valueOf(start), String.valueOf(end),
1007                                    String.valueOf(orderByComparator)
1008                            };
1009    
1010                    List<ServiceComponent> list = (List<ServiceComponent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1011                                    finderArgs, this);
1012    
1013                    if (list == null) {
1014                            Session session = null;
1015    
1016                            try {
1017                                    session = openSession();
1018    
1019                                    StringBundler query = null;
1020                                    String sql = null;
1021    
1022                                    if (orderByComparator != null) {
1023                                            query = new StringBundler(2 +
1024                                                            (orderByComparator.getOrderByFields().length * 3));
1025    
1026                                            query.append(_SQL_SELECT_SERVICECOMPONENT);
1027    
1028                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1029                                                    orderByComparator);
1030    
1031                                            sql = query.toString();
1032                                    }
1033                                    else {
1034                                            sql = _SQL_SELECT_SERVICECOMPONENT.concat(ServiceComponentModelImpl.ORDER_BY_JPQL);
1035                                    }
1036    
1037                                    Query q = session.createQuery(sql);
1038    
1039                                    if (orderByComparator == null) {
1040                                            list = (List<ServiceComponent>)QueryUtil.list(q,
1041                                                            getDialect(), start, end, false);
1042    
1043                                            Collections.sort(list);
1044                                    }
1045                                    else {
1046                                            list = (List<ServiceComponent>)QueryUtil.list(q,
1047                                                            getDialect(), start, end);
1048                                    }
1049                            }
1050                            catch (Exception e) {
1051                                    throw processException(e);
1052                            }
1053                            finally {
1054                                    if (list == null) {
1055                                            list = new ArrayList<ServiceComponent>();
1056                                    }
1057    
1058                                    cacheResult(list);
1059    
1060                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1061    
1062                                    closeSession(session);
1063                            }
1064                    }
1065    
1066                    return list;
1067            }
1068    
1069            /**
1070             * Removes all the service components where buildNamespace = &#63; from the database.
1071             *
1072             * @param buildNamespace the build namespace to search with
1073             * @throws SystemException if a system exception occurred
1074             */
1075            public void removeByBuildNamespace(String buildNamespace)
1076                    throws SystemException {
1077                    for (ServiceComponent serviceComponent : findByBuildNamespace(
1078                                    buildNamespace)) {
1079                            remove(serviceComponent);
1080                    }
1081            }
1082    
1083            /**
1084             * Removes the service component where buildNamespace = &#63; and buildNumber = &#63; from the database.
1085             *
1086             * @param buildNamespace the build namespace to search with
1087             * @param buildNumber the build number to search with
1088             * @throws SystemException if a system exception occurred
1089             */
1090            public void removeByBNS_BNU(String buildNamespace, long buildNumber)
1091                    throws NoSuchServiceComponentException, SystemException {
1092                    ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
1093                                    buildNumber);
1094    
1095                    remove(serviceComponent);
1096            }
1097    
1098            /**
1099             * Removes all the service components from the database.
1100             *
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public void removeAll() throws SystemException {
1104                    for (ServiceComponent serviceComponent : findAll()) {
1105                            remove(serviceComponent);
1106                    }
1107            }
1108    
1109            /**
1110             * Counts all the service components where buildNamespace = &#63;.
1111             *
1112             * @param buildNamespace the build namespace to search with
1113             * @return the number of matching service components
1114             * @throws SystemException if a system exception occurred
1115             */
1116            public int countByBuildNamespace(String buildNamespace)
1117                    throws SystemException {
1118                    Object[] finderArgs = new Object[] { buildNamespace };
1119    
1120                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1121                                    finderArgs, this);
1122    
1123                    if (count == null) {
1124                            Session session = null;
1125    
1126                            try {
1127                                    session = openSession();
1128    
1129                                    StringBundler query = new StringBundler(2);
1130    
1131                                    query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
1132    
1133                                    if (buildNamespace == null) {
1134                                            query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1);
1135                                    }
1136                                    else {
1137                                            if (buildNamespace.equals(StringPool.BLANK)) {
1138                                                    query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3);
1139                                            }
1140                                            else {
1141                                                    query.append(_FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2);
1142                                            }
1143                                    }
1144    
1145                                    String sql = query.toString();
1146    
1147                                    Query q = session.createQuery(sql);
1148    
1149                                    QueryPos qPos = QueryPos.getInstance(q);
1150    
1151                                    if (buildNamespace != null) {
1152                                            qPos.add(buildNamespace);
1153                                    }
1154    
1155                                    count = (Long)q.uniqueResult();
1156                            }
1157                            catch (Exception e) {
1158                                    throw processException(e);
1159                            }
1160                            finally {
1161                                    if (count == null) {
1162                                            count = Long.valueOf(0);
1163                                    }
1164    
1165                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BUILDNAMESPACE,
1166                                            finderArgs, count);
1167    
1168                                    closeSession(session);
1169                            }
1170                    }
1171    
1172                    return count.intValue();
1173            }
1174    
1175            /**
1176             * Counts all the service components where buildNamespace = &#63; and buildNumber = &#63;.
1177             *
1178             * @param buildNamespace the build namespace to search with
1179             * @param buildNumber the build number to search with
1180             * @return the number of matching service components
1181             * @throws SystemException if a system exception occurred
1182             */
1183            public int countByBNS_BNU(String buildNamespace, long buildNumber)
1184                    throws SystemException {
1185                    Object[] finderArgs = new Object[] { buildNamespace, buildNumber };
1186    
1187                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BNS_BNU,
1188                                    finderArgs, this);
1189    
1190                    if (count == null) {
1191                            Session session = null;
1192    
1193                            try {
1194                                    session = openSession();
1195    
1196                                    StringBundler query = new StringBundler(3);
1197    
1198                                    query.append(_SQL_COUNT_SERVICECOMPONENT_WHERE);
1199    
1200                                    if (buildNamespace == null) {
1201                                            query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1);
1202                                    }
1203                                    else {
1204                                            if (buildNamespace.equals(StringPool.BLANK)) {
1205                                                    query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3);
1206                                            }
1207                                            else {
1208                                                    query.append(_FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2);
1209                                            }
1210                                    }
1211    
1212                                    query.append(_FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2);
1213    
1214                                    String sql = query.toString();
1215    
1216                                    Query q = session.createQuery(sql);
1217    
1218                                    QueryPos qPos = QueryPos.getInstance(q);
1219    
1220                                    if (buildNamespace != null) {
1221                                            qPos.add(buildNamespace);
1222                                    }
1223    
1224                                    qPos.add(buildNumber);
1225    
1226                                    count = (Long)q.uniqueResult();
1227                            }
1228                            catch (Exception e) {
1229                                    throw processException(e);
1230                            }
1231                            finally {
1232                                    if (count == null) {
1233                                            count = Long.valueOf(0);
1234                                    }
1235    
1236                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BNS_BNU,
1237                                            finderArgs, count);
1238    
1239                                    closeSession(session);
1240                            }
1241                    }
1242    
1243                    return count.intValue();
1244            }
1245    
1246            /**
1247             * Counts all the service components.
1248             *
1249             * @return the number of service components
1250             * @throws SystemException if a system exception occurred
1251             */
1252            public int countAll() throws SystemException {
1253                    Object[] finderArgs = new Object[0];
1254    
1255                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1256                                    finderArgs, this);
1257    
1258                    if (count == null) {
1259                            Session session = null;
1260    
1261                            try {
1262                                    session = openSession();
1263    
1264                                    Query q = session.createQuery(_SQL_COUNT_SERVICECOMPONENT);
1265    
1266                                    count = (Long)q.uniqueResult();
1267                            }
1268                            catch (Exception e) {
1269                                    throw processException(e);
1270                            }
1271                            finally {
1272                                    if (count == null) {
1273                                            count = Long.valueOf(0);
1274                                    }
1275    
1276                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1277                                            count);
1278    
1279                                    closeSession(session);
1280                            }
1281                    }
1282    
1283                    return count.intValue();
1284            }
1285    
1286            /**
1287             * Initializes the service component persistence.
1288             */
1289            public void afterPropertiesSet() {
1290                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1291                                            com.liferay.portal.util.PropsUtil.get(
1292                                                    "value.object.listener.com.liferay.portal.model.ServiceComponent")));
1293    
1294                    if (listenerClassNames.length > 0) {
1295                            try {
1296                                    List<ModelListener<ServiceComponent>> listenersList = new ArrayList<ModelListener<ServiceComponent>>();
1297    
1298                                    for (String listenerClassName : listenerClassNames) {
1299                                            listenersList.add((ModelListener<ServiceComponent>)InstanceFactory.newInstance(
1300                                                            listenerClassName));
1301                                    }
1302    
1303                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1304                            }
1305                            catch (Exception e) {
1306                                    _log.error(e);
1307                            }
1308                    }
1309            }
1310    
1311            @BeanReference(type = AccountPersistence.class)
1312            protected AccountPersistence accountPersistence;
1313            @BeanReference(type = AddressPersistence.class)
1314            protected AddressPersistence addressPersistence;
1315            @BeanReference(type = BrowserTrackerPersistence.class)
1316            protected BrowserTrackerPersistence browserTrackerPersistence;
1317            @BeanReference(type = ClassNamePersistence.class)
1318            protected ClassNamePersistence classNamePersistence;
1319            @BeanReference(type = ClusterGroupPersistence.class)
1320            protected ClusterGroupPersistence clusterGroupPersistence;
1321            @BeanReference(type = CompanyPersistence.class)
1322            protected CompanyPersistence companyPersistence;
1323            @BeanReference(type = ContactPersistence.class)
1324            protected ContactPersistence contactPersistence;
1325            @BeanReference(type = CountryPersistence.class)
1326            protected CountryPersistence countryPersistence;
1327            @BeanReference(type = EmailAddressPersistence.class)
1328            protected EmailAddressPersistence emailAddressPersistence;
1329            @BeanReference(type = GroupPersistence.class)
1330            protected GroupPersistence groupPersistence;
1331            @BeanReference(type = ImagePersistence.class)
1332            protected ImagePersistence imagePersistence;
1333            @BeanReference(type = LayoutPersistence.class)
1334            protected LayoutPersistence layoutPersistence;
1335            @BeanReference(type = LayoutPrototypePersistence.class)
1336            protected LayoutPrototypePersistence layoutPrototypePersistence;
1337            @BeanReference(type = LayoutSetPersistence.class)
1338            protected LayoutSetPersistence layoutSetPersistence;
1339            @BeanReference(type = LayoutSetPrototypePersistence.class)
1340            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1341            @BeanReference(type = ListTypePersistence.class)
1342            protected ListTypePersistence listTypePersistence;
1343            @BeanReference(type = LockPersistence.class)
1344            protected LockPersistence lockPersistence;
1345            @BeanReference(type = MembershipRequestPersistence.class)
1346            protected MembershipRequestPersistence membershipRequestPersistence;
1347            @BeanReference(type = OrganizationPersistence.class)
1348            protected OrganizationPersistence organizationPersistence;
1349            @BeanReference(type = OrgGroupPermissionPersistence.class)
1350            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1351            @BeanReference(type = OrgGroupRolePersistence.class)
1352            protected OrgGroupRolePersistence orgGroupRolePersistence;
1353            @BeanReference(type = OrgLaborPersistence.class)
1354            protected OrgLaborPersistence orgLaborPersistence;
1355            @BeanReference(type = PasswordPolicyPersistence.class)
1356            protected PasswordPolicyPersistence passwordPolicyPersistence;
1357            @BeanReference(type = PasswordPolicyRelPersistence.class)
1358            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1359            @BeanReference(type = PasswordTrackerPersistence.class)
1360            protected PasswordTrackerPersistence passwordTrackerPersistence;
1361            @BeanReference(type = PermissionPersistence.class)
1362            protected PermissionPersistence permissionPersistence;
1363            @BeanReference(type = PhonePersistence.class)
1364            protected PhonePersistence phonePersistence;
1365            @BeanReference(type = PluginSettingPersistence.class)
1366            protected PluginSettingPersistence pluginSettingPersistence;
1367            @BeanReference(type = PortletPersistence.class)
1368            protected PortletPersistence portletPersistence;
1369            @BeanReference(type = PortletItemPersistence.class)
1370            protected PortletItemPersistence portletItemPersistence;
1371            @BeanReference(type = PortletPreferencesPersistence.class)
1372            protected PortletPreferencesPersistence portletPreferencesPersistence;
1373            @BeanReference(type = RegionPersistence.class)
1374            protected RegionPersistence regionPersistence;
1375            @BeanReference(type = ReleasePersistence.class)
1376            protected ReleasePersistence releasePersistence;
1377            @BeanReference(type = ResourcePersistence.class)
1378            protected ResourcePersistence resourcePersistence;
1379            @BeanReference(type = ResourceActionPersistence.class)
1380            protected ResourceActionPersistence resourceActionPersistence;
1381            @BeanReference(type = ResourceCodePersistence.class)
1382            protected ResourceCodePersistence resourceCodePersistence;
1383            @BeanReference(type = ResourcePermissionPersistence.class)
1384            protected ResourcePermissionPersistence resourcePermissionPersistence;
1385            @BeanReference(type = RolePersistence.class)
1386            protected RolePersistence rolePersistence;
1387            @BeanReference(type = ServiceComponentPersistence.class)
1388            protected ServiceComponentPersistence serviceComponentPersistence;
1389            @BeanReference(type = ShardPersistence.class)
1390            protected ShardPersistence shardPersistence;
1391            @BeanReference(type = SubscriptionPersistence.class)
1392            protected SubscriptionPersistence subscriptionPersistence;
1393            @BeanReference(type = TicketPersistence.class)
1394            protected TicketPersistence ticketPersistence;
1395            @BeanReference(type = TeamPersistence.class)
1396            protected TeamPersistence teamPersistence;
1397            @BeanReference(type = UserPersistence.class)
1398            protected UserPersistence userPersistence;
1399            @BeanReference(type = UserGroupPersistence.class)
1400            protected UserGroupPersistence userGroupPersistence;
1401            @BeanReference(type = UserGroupGroupRolePersistence.class)
1402            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1403            @BeanReference(type = UserGroupRolePersistence.class)
1404            protected UserGroupRolePersistence userGroupRolePersistence;
1405            @BeanReference(type = UserIdMapperPersistence.class)
1406            protected UserIdMapperPersistence userIdMapperPersistence;
1407            @BeanReference(type = UserTrackerPersistence.class)
1408            protected UserTrackerPersistence userTrackerPersistence;
1409            @BeanReference(type = UserTrackerPathPersistence.class)
1410            protected UserTrackerPathPersistence userTrackerPathPersistence;
1411            @BeanReference(type = WebDAVPropsPersistence.class)
1412            protected WebDAVPropsPersistence webDAVPropsPersistence;
1413            @BeanReference(type = WebsitePersistence.class)
1414            protected WebsitePersistence websitePersistence;
1415            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1416            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1417            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1418            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1419            private static final String _SQL_SELECT_SERVICECOMPONENT = "SELECT serviceComponent FROM ServiceComponent serviceComponent";
1420            private static final String _SQL_SELECT_SERVICECOMPONENT_WHERE = "SELECT serviceComponent FROM ServiceComponent serviceComponent WHERE ";
1421            private static final String _SQL_COUNT_SERVICECOMPONENT = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent";
1422            private static final String _SQL_COUNT_SERVICECOMPONENT_WHERE = "SELECT COUNT(serviceComponent) FROM ServiceComponent serviceComponent WHERE ";
1423            private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL";
1424            private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ?";
1425            private static final String _FINDER_COLUMN_BUILDNAMESPACE_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?)";
1426            private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_1 = "serviceComponent.buildNamespace IS NULL AND ";
1427            private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_2 = "serviceComponent.buildNamespace = ? AND ";
1428            private static final String _FINDER_COLUMN_BNS_BNU_BUILDNAMESPACE_3 = "(serviceComponent.buildNamespace IS NULL OR serviceComponent.buildNamespace = ?) AND ";
1429            private static final String _FINDER_COLUMN_BNS_BNU_BUILDNUMBER_2 = "serviceComponent.buildNumber = ?";
1430            private static final String _ORDER_BY_ENTITY_ALIAS = "serviceComponent.";
1431            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ServiceComponent exists with the primary key ";
1432            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ServiceComponent exists with the key {";
1433            private static Log _log = LogFactoryUtil.getLog(ServiceComponentPersistenceImpl.class);
1434    }