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