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