001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchReleaseException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.Release;
040    import com.liferay.portal.model.impl.ReleaseImpl;
041    import com.liferay.portal.model.impl.ReleaseModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the release service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ReleasePersistence
059     * @see ReleaseUtil
060     * @generated
061     */
062    public class ReleasePersistenceImpl extends BasePersistenceImpl<Release>
063            implements ReleasePersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link ReleaseUtil} to access the release persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ReleaseImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
075                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
076                            FINDER_CLASS_NAME_ENTITY, "fetchByServletContextName",
077                            new String[] { String.class.getName() },
078                            ReleaseModelImpl.SERVLETCONTEXTNAME_COLUMN_BITMASK);
079            public static final FinderPath FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
080                            ReleaseModelImpl.FINDER_CACHE_ENABLED, Long.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
082                            "countByServletContextName", new String[] { String.class.getName() });
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
084                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
087                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
090                            ReleaseModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092    
093            /**
094             * Caches the release in the entity cache if it is enabled.
095             *
096             * @param release the release
097             */
098            public void cacheResult(Release release) {
099                    EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
100                            ReleaseImpl.class, release.getPrimaryKey(), release);
101    
102                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
103                            new Object[] { release.getServletContextName() }, release);
104    
105                    release.resetOriginalValues();
106            }
107    
108            /**
109             * Caches the releases in the entity cache if it is enabled.
110             *
111             * @param releases the releases
112             */
113            public void cacheResult(List<Release> releases) {
114                    for (Release release : releases) {
115                            if (EntityCacheUtil.getResult(
116                                                    ReleaseModelImpl.ENTITY_CACHE_ENABLED,
117                                                    ReleaseImpl.class, release.getPrimaryKey()) == null) {
118                                    cacheResult(release);
119                            }
120                            else {
121                                    release.resetOriginalValues();
122                            }
123                    }
124            }
125    
126            /**
127             * Clears the cache for all releases.
128             *
129             * <p>
130             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
131             * </p>
132             */
133            @Override
134            public void clearCache() {
135                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
136                            CacheRegistryUtil.clear(ReleaseImpl.class.getName());
137                    }
138    
139                    EntityCacheUtil.clearCache(ReleaseImpl.class.getName());
140    
141                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
142                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
143                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
144            }
145    
146            /**
147             * Clears the cache for the release.
148             *
149             * <p>
150             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
151             * </p>
152             */
153            @Override
154            public void clearCache(Release release) {
155                    EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
156                            ReleaseImpl.class, release.getPrimaryKey());
157    
158                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
159                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
160    
161                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
162                            new Object[] { release.getServletContextName() });
163            }
164    
165            /**
166             * Creates a new release with the primary key. Does not add the release to the database.
167             *
168             * @param releaseId the primary key for the new release
169             * @return the new release
170             */
171            public Release create(long releaseId) {
172                    Release release = new ReleaseImpl();
173    
174                    release.setNew(true);
175                    release.setPrimaryKey(releaseId);
176    
177                    return release;
178            }
179    
180            /**
181             * Removes the release with the primary key from the database. Also notifies the appropriate model listeners.
182             *
183             * @param primaryKey the primary key of the release
184             * @return the release that was removed
185             * @throws com.liferay.portal.NoSuchModelException if a release with the primary key could not be found
186             * @throws SystemException if a system exception occurred
187             */
188            @Override
189            public Release remove(Serializable primaryKey)
190                    throws NoSuchModelException, SystemException {
191                    return remove(((Long)primaryKey).longValue());
192            }
193    
194            /**
195             * Removes the release with the primary key from the database. Also notifies the appropriate model listeners.
196             *
197             * @param releaseId the primary key of the release
198             * @return the release that was removed
199             * @throws com.liferay.portal.NoSuchReleaseException if a release with the primary key could not be found
200             * @throws SystemException if a system exception occurred
201             */
202            public Release remove(long releaseId)
203                    throws NoSuchReleaseException, SystemException {
204                    Session session = null;
205    
206                    try {
207                            session = openSession();
208    
209                            Release release = (Release)session.get(ReleaseImpl.class,
210                                            Long.valueOf(releaseId));
211    
212                            if (release == null) {
213                                    if (_log.isWarnEnabled()) {
214                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + releaseId);
215                                    }
216    
217                                    throw new NoSuchReleaseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
218                                            releaseId);
219                            }
220    
221                            return releasePersistence.remove(release);
222                    }
223                    catch (NoSuchReleaseException nsee) {
224                            throw nsee;
225                    }
226                    catch (Exception e) {
227                            throw processException(e);
228                    }
229                    finally {
230                            closeSession(session);
231                    }
232            }
233    
234            /**
235             * Removes the release from the database. Also notifies the appropriate model listeners.
236             *
237             * @param release the release
238             * @return the release that was removed
239             * @throws SystemException if a system exception occurred
240             */
241            @Override
242            public Release remove(Release release) throws SystemException {
243                    return super.remove(release);
244            }
245    
246            @Override
247            protected Release removeImpl(Release release) throws SystemException {
248                    release = toUnwrappedModel(release);
249    
250                    Session session = null;
251    
252                    try {
253                            session = openSession();
254    
255                            BatchSessionUtil.delete(session, release);
256                    }
257                    catch (Exception e) {
258                            throw processException(e);
259                    }
260                    finally {
261                            closeSession(session);
262                    }
263    
264                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
265                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
266    
267                    ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl)release;
268    
269                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
270                            new Object[] { releaseModelImpl.getServletContextName() });
271    
272                    EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
273                            ReleaseImpl.class, release.getPrimaryKey());
274    
275                    return release;
276            }
277    
278            @Override
279            public Release updateImpl(com.liferay.portal.model.Release release,
280                    boolean merge) throws SystemException {
281                    release = toUnwrappedModel(release);
282    
283                    boolean isNew = release.isNew();
284    
285                    ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl)release;
286    
287                    Session session = null;
288    
289                    try {
290                            session = openSession();
291    
292                            BatchSessionUtil.update(session, release, merge);
293    
294                            release.setNew(false);
295                    }
296                    catch (Exception e) {
297                            throw processException(e);
298                    }
299                    finally {
300                            closeSession(session);
301                    }
302    
303                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
304    
305                    if (isNew || !ReleaseModelImpl.COLUMN_BITMASK_ENABLED) {
306                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
307                    }
308    
309                    EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
310                            ReleaseImpl.class, release.getPrimaryKey(), release);
311    
312                    if (isNew) {
313                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
314                                    new Object[] { release.getServletContextName() }, release);
315                    }
316                    else {
317                            if ((releaseModelImpl.getColumnBitmask() &
318                                            FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) {
319                                    Object[] args = new Object[] {
320                                                    releaseModelImpl.getOriginalServletContextName()
321                                            };
322    
323                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
324                                            args);
325                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
326                                            args);
327    
328                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
329                                            new Object[] { release.getServletContextName() }, release);
330                            }
331                    }
332    
333                    return release;
334            }
335    
336            protected Release toUnwrappedModel(Release release) {
337                    if (release instanceof ReleaseImpl) {
338                            return release;
339                    }
340    
341                    ReleaseImpl releaseImpl = new ReleaseImpl();
342    
343                    releaseImpl.setNew(release.isNew());
344                    releaseImpl.setPrimaryKey(release.getPrimaryKey());
345    
346                    releaseImpl.setReleaseId(release.getReleaseId());
347                    releaseImpl.setCreateDate(release.getCreateDate());
348                    releaseImpl.setModifiedDate(release.getModifiedDate());
349                    releaseImpl.setServletContextName(release.getServletContextName());
350                    releaseImpl.setBuildNumber(release.getBuildNumber());
351                    releaseImpl.setBuildDate(release.getBuildDate());
352                    releaseImpl.setVerified(release.isVerified());
353                    releaseImpl.setTestString(release.getTestString());
354    
355                    return releaseImpl;
356            }
357    
358            /**
359             * Returns the release with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
360             *
361             * @param primaryKey the primary key of the release
362             * @return the release
363             * @throws com.liferay.portal.NoSuchModelException if a release with the primary key could not be found
364             * @throws SystemException if a system exception occurred
365             */
366            @Override
367            public Release findByPrimaryKey(Serializable primaryKey)
368                    throws NoSuchModelException, SystemException {
369                    return findByPrimaryKey(((Long)primaryKey).longValue());
370            }
371    
372            /**
373             * Returns the release with the primary key or throws a {@link com.liferay.portal.NoSuchReleaseException} if it could not be found.
374             *
375             * @param releaseId the primary key of the release
376             * @return the release
377             * @throws com.liferay.portal.NoSuchReleaseException if a release with the primary key could not be found
378             * @throws SystemException if a system exception occurred
379             */
380            public Release findByPrimaryKey(long releaseId)
381                    throws NoSuchReleaseException, SystemException {
382                    Release release = fetchByPrimaryKey(releaseId);
383    
384                    if (release == null) {
385                            if (_log.isWarnEnabled()) {
386                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + releaseId);
387                            }
388    
389                            throw new NoSuchReleaseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
390                                    releaseId);
391                    }
392    
393                    return release;
394            }
395    
396            /**
397             * Returns the release with the primary key or returns <code>null</code> if it could not be found.
398             *
399             * @param primaryKey the primary key of the release
400             * @return the release, or <code>null</code> if a release with the primary key could not be found
401             * @throws SystemException if a system exception occurred
402             */
403            @Override
404            public Release fetchByPrimaryKey(Serializable primaryKey)
405                    throws SystemException {
406                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
407            }
408    
409            /**
410             * Returns the release with the primary key or returns <code>null</code> if it could not be found.
411             *
412             * @param releaseId the primary key of the release
413             * @return the release, or <code>null</code> if a release with the primary key could not be found
414             * @throws SystemException if a system exception occurred
415             */
416            public Release fetchByPrimaryKey(long releaseId) throws SystemException {
417                    Release release = (Release)EntityCacheUtil.getResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
418                                    ReleaseImpl.class, releaseId);
419    
420                    if (release == _nullRelease) {
421                            return null;
422                    }
423    
424                    if (release == null) {
425                            Session session = null;
426    
427                            boolean hasException = false;
428    
429                            try {
430                                    session = openSession();
431    
432                                    release = (Release)session.get(ReleaseImpl.class,
433                                                    Long.valueOf(releaseId));
434                            }
435                            catch (Exception e) {
436                                    hasException = true;
437    
438                                    throw processException(e);
439                            }
440                            finally {
441                                    if (release != null) {
442                                            cacheResult(release);
443                                    }
444                                    else if (!hasException) {
445                                            EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
446                                                    ReleaseImpl.class, releaseId, _nullRelease);
447                                    }
448    
449                                    closeSession(session);
450                            }
451                    }
452    
453                    return release;
454            }
455    
456            /**
457             * Returns the release where servletContextName = &#63; or throws a {@link com.liferay.portal.NoSuchReleaseException} if it could not be found.
458             *
459             * @param servletContextName the servlet context name
460             * @return the matching release
461             * @throws com.liferay.portal.NoSuchReleaseException if a matching release could not be found
462             * @throws SystemException if a system exception occurred
463             */
464            public Release findByServletContextName(String servletContextName)
465                    throws NoSuchReleaseException, SystemException {
466                    Release release = fetchByServletContextName(servletContextName);
467    
468                    if (release == null) {
469                            StringBundler msg = new StringBundler(4);
470    
471                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
472    
473                            msg.append("servletContextName=");
474                            msg.append(servletContextName);
475    
476                            msg.append(StringPool.CLOSE_CURLY_BRACE);
477    
478                            if (_log.isWarnEnabled()) {
479                                    _log.warn(msg.toString());
480                            }
481    
482                            throw new NoSuchReleaseException(msg.toString());
483                    }
484    
485                    return release;
486            }
487    
488            /**
489             * Returns the release where servletContextName = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
490             *
491             * @param servletContextName the servlet context name
492             * @return the matching release, or <code>null</code> if a matching release could not be found
493             * @throws SystemException if a system exception occurred
494             */
495            public Release fetchByServletContextName(String servletContextName)
496                    throws SystemException {
497                    return fetchByServletContextName(servletContextName, true);
498            }
499    
500            /**
501             * Returns the release where servletContextName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
502             *
503             * @param servletContextName the servlet context name
504             * @param retrieveFromCache whether to use the finder cache
505             * @return the matching release, or <code>null</code> if a matching release could not be found
506             * @throws SystemException if a system exception occurred
507             */
508            public Release fetchByServletContextName(String servletContextName,
509                    boolean retrieveFromCache) throws SystemException {
510                    Object[] finderArgs = new Object[] { servletContextName };
511    
512                    Object result = null;
513    
514                    if (retrieveFromCache) {
515                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
516                                            finderArgs, this);
517                    }
518    
519                    if (result == null) {
520                            StringBundler query = new StringBundler(2);
521    
522                            query.append(_SQL_SELECT_RELEASE_WHERE);
523    
524                            if (servletContextName == null) {
525                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
526                            }
527                            else {
528                                    if (servletContextName.equals(StringPool.BLANK)) {
529                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
530                                    }
531                                    else {
532                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
533                                    }
534                            }
535    
536                            String sql = query.toString();
537    
538                            Session session = null;
539    
540                            try {
541                                    session = openSession();
542    
543                                    Query q = session.createQuery(sql);
544    
545                                    QueryPos qPos = QueryPos.getInstance(q);
546    
547                                    if (servletContextName != null) {
548                                            qPos.add(servletContextName);
549                                    }
550    
551                                    List<Release> list = q.list();
552    
553                                    result = list;
554    
555                                    Release release = null;
556    
557                                    if (list.isEmpty()) {
558                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
559                                                    finderArgs, list);
560                                    }
561                                    else {
562                                            release = list.get(0);
563    
564                                            cacheResult(release);
565    
566                                            if ((release.getServletContextName() == null) ||
567                                                            !release.getServletContextName()
568                                                                                    .equals(servletContextName)) {
569                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
570                                                            finderArgs, release);
571                                            }
572                                    }
573    
574                                    return release;
575                            }
576                            catch (Exception e) {
577                                    throw processException(e);
578                            }
579                            finally {
580                                    if (result == null) {
581                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
582                                                    finderArgs);
583                                    }
584    
585                                    closeSession(session);
586                            }
587                    }
588                    else {
589                            if (result instanceof List<?>) {
590                                    return null;
591                            }
592                            else {
593                                    return (Release)result;
594                            }
595                    }
596            }
597    
598            /**
599             * Returns all the releases.
600             *
601             * @return the releases
602             * @throws SystemException if a system exception occurred
603             */
604            public List<Release> findAll() throws SystemException {
605                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
606            }
607    
608            /**
609             * Returns a range of all the releases.
610             *
611             * <p>
612             * 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.
613             * </p>
614             *
615             * @param start the lower bound of the range of releases
616             * @param end the upper bound of the range of releases (not inclusive)
617             * @return the range of releases
618             * @throws SystemException if a system exception occurred
619             */
620            public List<Release> findAll(int start, int end) throws SystemException {
621                    return findAll(start, end, null);
622            }
623    
624            /**
625             * Returns an ordered range of all the releases.
626             *
627             * <p>
628             * 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.
629             * </p>
630             *
631             * @param start the lower bound of the range of releases
632             * @param end the upper bound of the range of releases (not inclusive)
633             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
634             * @return the ordered range of releases
635             * @throws SystemException if a system exception occurred
636             */
637            public List<Release> findAll(int start, int end,
638                    OrderByComparator orderByComparator) throws SystemException {
639                    FinderPath finderPath = null;
640                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
641    
642                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
643                                    (orderByComparator == null)) {
644                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
645                            finderArgs = FINDER_ARGS_EMPTY;
646                    }
647                    else {
648                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
649                            finderArgs = new Object[] { start, end, orderByComparator };
650                    }
651    
652                    List<Release> list = (List<Release>)FinderCacheUtil.getResult(finderPath,
653                                    finderArgs, this);
654    
655                    if (list == null) {
656                            StringBundler query = null;
657                            String sql = null;
658    
659                            if (orderByComparator != null) {
660                                    query = new StringBundler(2 +
661                                                    (orderByComparator.getOrderByFields().length * 3));
662    
663                                    query.append(_SQL_SELECT_RELEASE);
664    
665                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
666                                            orderByComparator);
667    
668                                    sql = query.toString();
669                            }
670                            else {
671                                    sql = _SQL_SELECT_RELEASE;
672                            }
673    
674                            Session session = null;
675    
676                            try {
677                                    session = openSession();
678    
679                                    Query q = session.createQuery(sql);
680    
681                                    if (orderByComparator == null) {
682                                            list = (List<Release>)QueryUtil.list(q, getDialect(),
683                                                            start, end, false);
684    
685                                            Collections.sort(list);
686                                    }
687                                    else {
688                                            list = (List<Release>)QueryUtil.list(q, getDialect(),
689                                                            start, end);
690                                    }
691                            }
692                            catch (Exception e) {
693                                    throw processException(e);
694                            }
695                            finally {
696                                    if (list == null) {
697                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
698                                    }
699                                    else {
700                                            cacheResult(list);
701    
702                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
703                                    }
704    
705                                    closeSession(session);
706                            }
707                    }
708    
709                    return list;
710            }
711    
712            /**
713             * Removes the release where servletContextName = &#63; from the database.
714             *
715             * @param servletContextName the servlet context name
716             * @throws SystemException if a system exception occurred
717             */
718            public void removeByServletContextName(String servletContextName)
719                    throws NoSuchReleaseException, SystemException {
720                    Release release = findByServletContextName(servletContextName);
721    
722                    releasePersistence.remove(release);
723            }
724    
725            /**
726             * Removes all the releases from the database.
727             *
728             * @throws SystemException if a system exception occurred
729             */
730            public void removeAll() throws SystemException {
731                    for (Release release : findAll()) {
732                            releasePersistence.remove(release);
733                    }
734            }
735    
736            /**
737             * Returns the number of releases where servletContextName = &#63;.
738             *
739             * @param servletContextName the servlet context name
740             * @return the number of matching releases
741             * @throws SystemException if a system exception occurred
742             */
743            public int countByServletContextName(String servletContextName)
744                    throws SystemException {
745                    Object[] finderArgs = new Object[] { servletContextName };
746    
747                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
748                                    finderArgs, this);
749    
750                    if (count == null) {
751                            StringBundler query = new StringBundler(2);
752    
753                            query.append(_SQL_COUNT_RELEASE_WHERE);
754    
755                            if (servletContextName == null) {
756                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
757                            }
758                            else {
759                                    if (servletContextName.equals(StringPool.BLANK)) {
760                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
761                                    }
762                                    else {
763                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
764                                    }
765                            }
766    
767                            String sql = query.toString();
768    
769                            Session session = null;
770    
771                            try {
772                                    session = openSession();
773    
774                                    Query q = session.createQuery(sql);
775    
776                                    QueryPos qPos = QueryPos.getInstance(q);
777    
778                                    if (servletContextName != null) {
779                                            qPos.add(servletContextName);
780                                    }
781    
782                                    count = (Long)q.uniqueResult();
783                            }
784                            catch (Exception e) {
785                                    throw processException(e);
786                            }
787                            finally {
788                                    if (count == null) {
789                                            count = Long.valueOf(0);
790                                    }
791    
792                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
793                                            finderArgs, count);
794    
795                                    closeSession(session);
796                            }
797                    }
798    
799                    return count.intValue();
800            }
801    
802            /**
803             * Returns the number of releases.
804             *
805             * @return the number of releases
806             * @throws SystemException if a system exception occurred
807             */
808            public int countAll() throws SystemException {
809                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
810                                    FINDER_ARGS_EMPTY, this);
811    
812                    if (count == null) {
813                            Session session = null;
814    
815                            try {
816                                    session = openSession();
817    
818                                    Query q = session.createQuery(_SQL_COUNT_RELEASE);
819    
820                                    count = (Long)q.uniqueResult();
821                            }
822                            catch (Exception e) {
823                                    throw processException(e);
824                            }
825                            finally {
826                                    if (count == null) {
827                                            count = Long.valueOf(0);
828                                    }
829    
830                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
831                                            FINDER_ARGS_EMPTY, count);
832    
833                                    closeSession(session);
834                            }
835                    }
836    
837                    return count.intValue();
838            }
839    
840            /**
841             * Initializes the release persistence.
842             */
843            public void afterPropertiesSet() {
844                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
845                                            com.liferay.portal.util.PropsUtil.get(
846                                                    "value.object.listener.com.liferay.portal.model.Release")));
847    
848                    if (listenerClassNames.length > 0) {
849                            try {
850                                    List<ModelListener<Release>> listenersList = new ArrayList<ModelListener<Release>>();
851    
852                                    for (String listenerClassName : listenerClassNames) {
853                                            listenersList.add((ModelListener<Release>)InstanceFactory.newInstance(
854                                                            listenerClassName));
855                                    }
856    
857                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
858                            }
859                            catch (Exception e) {
860                                    _log.error(e);
861                            }
862                    }
863            }
864    
865            public void destroy() {
866                    EntityCacheUtil.removeCache(ReleaseImpl.class.getName());
867                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
868                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
869            }
870    
871            @BeanReference(type = AccountPersistence.class)
872            protected AccountPersistence accountPersistence;
873            @BeanReference(type = AddressPersistence.class)
874            protected AddressPersistence addressPersistence;
875            @BeanReference(type = BrowserTrackerPersistence.class)
876            protected BrowserTrackerPersistence browserTrackerPersistence;
877            @BeanReference(type = ClassNamePersistence.class)
878            protected ClassNamePersistence classNamePersistence;
879            @BeanReference(type = ClusterGroupPersistence.class)
880            protected ClusterGroupPersistence clusterGroupPersistence;
881            @BeanReference(type = CompanyPersistence.class)
882            protected CompanyPersistence companyPersistence;
883            @BeanReference(type = ContactPersistence.class)
884            protected ContactPersistence contactPersistence;
885            @BeanReference(type = CountryPersistence.class)
886            protected CountryPersistence countryPersistence;
887            @BeanReference(type = EmailAddressPersistence.class)
888            protected EmailAddressPersistence emailAddressPersistence;
889            @BeanReference(type = GroupPersistence.class)
890            protected GroupPersistence groupPersistence;
891            @BeanReference(type = ImagePersistence.class)
892            protected ImagePersistence imagePersistence;
893            @BeanReference(type = LayoutPersistence.class)
894            protected LayoutPersistence layoutPersistence;
895            @BeanReference(type = LayoutBranchPersistence.class)
896            protected LayoutBranchPersistence layoutBranchPersistence;
897            @BeanReference(type = LayoutPrototypePersistence.class)
898            protected LayoutPrototypePersistence layoutPrototypePersistence;
899            @BeanReference(type = LayoutRevisionPersistence.class)
900            protected LayoutRevisionPersistence layoutRevisionPersistence;
901            @BeanReference(type = LayoutSetPersistence.class)
902            protected LayoutSetPersistence layoutSetPersistence;
903            @BeanReference(type = LayoutSetBranchPersistence.class)
904            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
905            @BeanReference(type = LayoutSetPrototypePersistence.class)
906            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
907            @BeanReference(type = ListTypePersistence.class)
908            protected ListTypePersistence listTypePersistence;
909            @BeanReference(type = LockPersistence.class)
910            protected LockPersistence lockPersistence;
911            @BeanReference(type = MembershipRequestPersistence.class)
912            protected MembershipRequestPersistence membershipRequestPersistence;
913            @BeanReference(type = OrganizationPersistence.class)
914            protected OrganizationPersistence organizationPersistence;
915            @BeanReference(type = OrgGroupPermissionPersistence.class)
916            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
917            @BeanReference(type = OrgGroupRolePersistence.class)
918            protected OrgGroupRolePersistence orgGroupRolePersistence;
919            @BeanReference(type = OrgLaborPersistence.class)
920            protected OrgLaborPersistence orgLaborPersistence;
921            @BeanReference(type = PasswordPolicyPersistence.class)
922            protected PasswordPolicyPersistence passwordPolicyPersistence;
923            @BeanReference(type = PasswordPolicyRelPersistence.class)
924            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
925            @BeanReference(type = PasswordTrackerPersistence.class)
926            protected PasswordTrackerPersistence passwordTrackerPersistence;
927            @BeanReference(type = PermissionPersistence.class)
928            protected PermissionPersistence permissionPersistence;
929            @BeanReference(type = PhonePersistence.class)
930            protected PhonePersistence phonePersistence;
931            @BeanReference(type = PluginSettingPersistence.class)
932            protected PluginSettingPersistence pluginSettingPersistence;
933            @BeanReference(type = PortalPreferencesPersistence.class)
934            protected PortalPreferencesPersistence portalPreferencesPersistence;
935            @BeanReference(type = PortletPersistence.class)
936            protected PortletPersistence portletPersistence;
937            @BeanReference(type = PortletItemPersistence.class)
938            protected PortletItemPersistence portletItemPersistence;
939            @BeanReference(type = PortletPreferencesPersistence.class)
940            protected PortletPreferencesPersistence portletPreferencesPersistence;
941            @BeanReference(type = RegionPersistence.class)
942            protected RegionPersistence regionPersistence;
943            @BeanReference(type = ReleasePersistence.class)
944            protected ReleasePersistence releasePersistence;
945            @BeanReference(type = RepositoryPersistence.class)
946            protected RepositoryPersistence repositoryPersistence;
947            @BeanReference(type = RepositoryEntryPersistence.class)
948            protected RepositoryEntryPersistence repositoryEntryPersistence;
949            @BeanReference(type = ResourcePersistence.class)
950            protected ResourcePersistence resourcePersistence;
951            @BeanReference(type = ResourceActionPersistence.class)
952            protected ResourceActionPersistence resourceActionPersistence;
953            @BeanReference(type = ResourceBlockPersistence.class)
954            protected ResourceBlockPersistence resourceBlockPersistence;
955            @BeanReference(type = ResourceBlockPermissionPersistence.class)
956            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
957            @BeanReference(type = ResourceCodePersistence.class)
958            protected ResourceCodePersistence resourceCodePersistence;
959            @BeanReference(type = ResourcePermissionPersistence.class)
960            protected ResourcePermissionPersistence resourcePermissionPersistence;
961            @BeanReference(type = ResourceTypePermissionPersistence.class)
962            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
963            @BeanReference(type = RolePersistence.class)
964            protected RolePersistence rolePersistence;
965            @BeanReference(type = ServiceComponentPersistence.class)
966            protected ServiceComponentPersistence serviceComponentPersistence;
967            @BeanReference(type = ShardPersistence.class)
968            protected ShardPersistence shardPersistence;
969            @BeanReference(type = SubscriptionPersistence.class)
970            protected SubscriptionPersistence subscriptionPersistence;
971            @BeanReference(type = TeamPersistence.class)
972            protected TeamPersistence teamPersistence;
973            @BeanReference(type = TicketPersistence.class)
974            protected TicketPersistence ticketPersistence;
975            @BeanReference(type = UserPersistence.class)
976            protected UserPersistence userPersistence;
977            @BeanReference(type = UserGroupPersistence.class)
978            protected UserGroupPersistence userGroupPersistence;
979            @BeanReference(type = UserGroupGroupRolePersistence.class)
980            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
981            @BeanReference(type = UserGroupRolePersistence.class)
982            protected UserGroupRolePersistence userGroupRolePersistence;
983            @BeanReference(type = UserIdMapperPersistence.class)
984            protected UserIdMapperPersistence userIdMapperPersistence;
985            @BeanReference(type = UserNotificationEventPersistence.class)
986            protected UserNotificationEventPersistence userNotificationEventPersistence;
987            @BeanReference(type = UserTrackerPersistence.class)
988            protected UserTrackerPersistence userTrackerPersistence;
989            @BeanReference(type = UserTrackerPathPersistence.class)
990            protected UserTrackerPathPersistence userTrackerPathPersistence;
991            @BeanReference(type = VirtualHostPersistence.class)
992            protected VirtualHostPersistence virtualHostPersistence;
993            @BeanReference(type = WebDAVPropsPersistence.class)
994            protected WebDAVPropsPersistence webDAVPropsPersistence;
995            @BeanReference(type = WebsitePersistence.class)
996            protected WebsitePersistence websitePersistence;
997            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
998            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
999            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1000            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1001            private static final String _SQL_SELECT_RELEASE = "SELECT release FROM Release release";
1002            private static final String _SQL_SELECT_RELEASE_WHERE = "SELECT release FROM Release release WHERE ";
1003            private static final String _SQL_COUNT_RELEASE = "SELECT COUNT(release) FROM Release release";
1004            private static final String _SQL_COUNT_RELEASE_WHERE = "SELECT COUNT(release) FROM Release release WHERE ";
1005            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1 =
1006                    "release.servletContextName IS NULL";
1007            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2 =
1008                    "release.servletContextName = ?";
1009            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3 =
1010                    "(release.servletContextName IS NULL OR release.servletContextName = ?)";
1011            private static final String _ORDER_BY_ENTITY_ALIAS = "release.";
1012            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Release exists with the primary key ";
1013            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Release exists with the key {";
1014            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1015            private static Log _log = LogFactoryUtil.getLog(ReleasePersistenceImpl.class);
1016            private static Release _nullRelease = new ReleaseImpl() {
1017                            @Override
1018                            public Object clone() {
1019                                    return this;
1020                            }
1021    
1022                            @Override
1023                            public CacheModel<Release> toCacheModel() {
1024                                    return _nullReleaseCacheModel;
1025                            }
1026                    };
1027    
1028            private static CacheModel<Release> _nullReleaseCacheModel = new CacheModel<Release>() {
1029                            public Release toEntityModel() {
1030                                    return _nullRelease;
1031                            }
1032                    };
1033    }