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