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