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