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