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