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