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