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