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