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