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