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