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