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