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