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