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