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