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