001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchReleaseException;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.Validator;
035    import com.liferay.portal.model.CacheModel;
036    import com.liferay.portal.model.MVCCModel;
037    import com.liferay.portal.model.Release;
038    import com.liferay.portal.model.impl.ReleaseImpl;
039    import com.liferay.portal.model.impl.ReleaseModelImpl;
040    import com.liferay.portal.service.ServiceContext;
041    import com.liferay.portal.service.ServiceContextThreadLocal;
042    import com.liferay.portal.service.persistence.ReleasePersistence;
043    
044    import java.io.Serializable;
045    
046    import java.util.Collections;
047    import java.util.Date;
048    import java.util.HashMap;
049    import java.util.HashSet;
050    import java.util.Iterator;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the release service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see ReleasePersistence
064     * @see com.liferay.portal.service.persistence.ReleaseUtil
065     * @generated
066     */
067    @ProviderType
068    public class ReleasePersistenceImpl extends BasePersistenceImpl<Release>
069            implements ReleasePersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = ReleaseImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
081                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
084                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
087                            ReleaseModelImpl.FINDER_CACHE_ENABLED, Long.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089            public static final FinderPath FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
090                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
091                            FINDER_CLASS_NAME_ENTITY, "fetchByServletContextName",
092                            new String[] { String.class.getName() },
093                            ReleaseModelImpl.SERVLETCONTEXTNAME_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
095                            ReleaseModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
097                            "countByServletContextName", new String[] { String.class.getName() });
098    
099            /**
100             * Returns the release where servletContextName = &#63; or throws a {@link NoSuchReleaseException} if it could not be found.
101             *
102             * @param servletContextName the servlet context name
103             * @return the matching release
104             * @throws NoSuchReleaseException if a matching release could not be found
105             */
106            @Override
107            public Release findByServletContextName(String servletContextName)
108                    throws NoSuchReleaseException {
109                    Release release = fetchByServletContextName(servletContextName);
110    
111                    if (release == null) {
112                            StringBundler msg = new StringBundler(4);
113    
114                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
115    
116                            msg.append("servletContextName=");
117                            msg.append(servletContextName);
118    
119                            msg.append(StringPool.CLOSE_CURLY_BRACE);
120    
121                            if (_log.isWarnEnabled()) {
122                                    _log.warn(msg.toString());
123                            }
124    
125                            throw new NoSuchReleaseException(msg.toString());
126                    }
127    
128                    return release;
129            }
130    
131            /**
132             * Returns the release where servletContextName = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
133             *
134             * @param servletContextName the servlet context name
135             * @return the matching release, or <code>null</code> if a matching release could not be found
136             */
137            @Override
138            public Release fetchByServletContextName(String servletContextName) {
139                    return fetchByServletContextName(servletContextName, true);
140            }
141    
142            /**
143             * Returns the release where servletContextName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
144             *
145             * @param servletContextName the servlet context name
146             * @param retrieveFromCache whether to use the finder cache
147             * @return the matching release, or <code>null</code> if a matching release could not be found
148             */
149            @Override
150            public Release fetchByServletContextName(String servletContextName,
151                    boolean retrieveFromCache) {
152                    Object[] finderArgs = new Object[] { servletContextName };
153    
154                    Object result = null;
155    
156                    if (retrieveFromCache) {
157                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
158                                            finderArgs, this);
159                    }
160    
161                    if (result instanceof Release) {
162                            Release release = (Release)result;
163    
164                            if (!Validator.equals(servletContextName,
165                                                    release.getServletContextName())) {
166                                    result = null;
167                            }
168                    }
169    
170                    if (result == null) {
171                            StringBundler query = new StringBundler(3);
172    
173                            query.append(_SQL_SELECT_RELEASE_WHERE);
174    
175                            boolean bindServletContextName = false;
176    
177                            if (servletContextName == null) {
178                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
179                            }
180                            else if (servletContextName.equals(StringPool.BLANK)) {
181                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
182                            }
183                            else {
184                                    bindServletContextName = true;
185    
186                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
187                            }
188    
189                            String sql = query.toString();
190    
191                            Session session = null;
192    
193                            try {
194                                    session = openSession();
195    
196                                    Query q = session.createQuery(sql);
197    
198                                    QueryPos qPos = QueryPos.getInstance(q);
199    
200                                    if (bindServletContextName) {
201                                            qPos.add(StringUtil.toLowerCase(servletContextName));
202                                    }
203    
204                                    List<Release> list = q.list();
205    
206                                    if (list.isEmpty()) {
207                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
208                                                    finderArgs, list);
209                                    }
210                                    else {
211                                            Release release = list.get(0);
212    
213                                            result = release;
214    
215                                            cacheResult(release);
216    
217                                            if ((release.getServletContextName() == null) ||
218                                                            !release.getServletContextName()
219                                                                                    .equals(servletContextName)) {
220                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
221                                                            finderArgs, release);
222                                            }
223                                    }
224                            }
225                            catch (Exception e) {
226                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
227                                            finderArgs);
228    
229                                    throw processException(e);
230                            }
231                            finally {
232                                    closeSession(session);
233                            }
234                    }
235    
236                    if (result instanceof List<?>) {
237                            return null;
238                    }
239                    else {
240                            return (Release)result;
241                    }
242            }
243    
244            /**
245             * Removes the release where servletContextName = &#63; from the database.
246             *
247             * @param servletContextName the servlet context name
248             * @return the release that was removed
249             */
250            @Override
251            public Release removeByServletContextName(String servletContextName)
252                    throws NoSuchReleaseException {
253                    Release release = findByServletContextName(servletContextName);
254    
255                    return remove(release);
256            }
257    
258            /**
259             * Returns the number of releases where servletContextName = &#63;.
260             *
261             * @param servletContextName the servlet context name
262             * @return the number of matching releases
263             */
264            @Override
265            public int countByServletContextName(String servletContextName) {
266                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME;
267    
268                    Object[] finderArgs = new Object[] { servletContextName };
269    
270                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
271                                    this);
272    
273                    if (count == null) {
274                            StringBundler query = new StringBundler(2);
275    
276                            query.append(_SQL_COUNT_RELEASE_WHERE);
277    
278                            boolean bindServletContextName = false;
279    
280                            if (servletContextName == null) {
281                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
282                            }
283                            else if (servletContextName.equals(StringPool.BLANK)) {
284                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
285                            }
286                            else {
287                                    bindServletContextName = true;
288    
289                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
290                            }
291    
292                            String sql = query.toString();
293    
294                            Session session = null;
295    
296                            try {
297                                    session = openSession();
298    
299                                    Query q = session.createQuery(sql);
300    
301                                    QueryPos qPos = QueryPos.getInstance(q);
302    
303                                    if (bindServletContextName) {
304                                            qPos.add(StringUtil.toLowerCase(servletContextName));
305                                    }
306    
307                                    count = (Long)q.uniqueResult();
308    
309                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
310                            }
311                            catch (Exception e) {
312                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
313    
314                                    throw processException(e);
315                            }
316                            finally {
317                                    closeSession(session);
318                            }
319                    }
320    
321                    return count.intValue();
322            }
323    
324            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1 =
325                    "release.servletContextName IS NULL";
326            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2 =
327                    "lower(release.servletContextName) = ?";
328            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3 =
329                    "(release.servletContextName IS NULL OR release.servletContextName = '')";
330    
331            public ReleasePersistenceImpl() {
332                    setModelClass(Release.class);
333            }
334    
335            /**
336             * Caches the release in the entity cache if it is enabled.
337             *
338             * @param release the release
339             */
340            @Override
341            public void cacheResult(Release release) {
342                    EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
343                            ReleaseImpl.class, release.getPrimaryKey(), release);
344    
345                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
346                            new Object[] { release.getServletContextName() }, release);
347    
348                    release.resetOriginalValues();
349            }
350    
351            /**
352             * Caches the releases in the entity cache if it is enabled.
353             *
354             * @param releases the releases
355             */
356            @Override
357            public void cacheResult(List<Release> releases) {
358                    for (Release release : releases) {
359                            if (EntityCacheUtil.getResult(
360                                                    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 com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
375             * </p>
376             */
377            @Override
378            public void clearCache() {
379                    EntityCacheUtil.clearCache(ReleaseImpl.class);
380    
381                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
382                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
383                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
384            }
385    
386            /**
387             * Clears the cache for the release.
388             *
389             * <p>
390             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
391             * </p>
392             */
393            @Override
394            public void clearCache(Release release) {
395                    EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
396                            ReleaseImpl.class, release.getPrimaryKey());
397    
398                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
399                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
400    
401                    clearUniqueFindersCache(release);
402            }
403    
404            @Override
405            public void clearCache(List<Release> releases) {
406                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
407                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
408    
409                    for (Release release : releases) {
410                            EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
411                                    ReleaseImpl.class, release.getPrimaryKey());
412    
413                            clearUniqueFindersCache(release);
414                    }
415            }
416    
417            protected void cacheUniqueFindersCache(Release release) {
418                    if (release.isNew()) {
419                            Object[] args = new Object[] { release.getServletContextName() };
420    
421                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
422                                    args, Long.valueOf(1));
423                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
424                                    args, release);
425                    }
426                    else {
427                            ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl)release;
428    
429                            if ((releaseModelImpl.getColumnBitmask() &
430                                            FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) {
431                                    Object[] args = new Object[] { release.getServletContextName() };
432    
433                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
434                                            args, Long.valueOf(1));
435                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
436                                            args, release);
437                            }
438                    }
439            }
440    
441            protected void clearUniqueFindersCache(Release release) {
442                    ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl)release;
443    
444                    Object[] args = new Object[] { release.getServletContextName() };
445    
446                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
447                            args);
448                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
449                            args);
450    
451                    if ((releaseModelImpl.getColumnBitmask() &
452                                    FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) {
453                            args = new Object[] { releaseModelImpl.getOriginalServletContextName() };
454    
455                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
456                                    args);
457                            FinderCacheUtil.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.isWarnEnabled()) {
509                                            _log.warn(_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                                    session.merge(release);
603                            }
604                    }
605                    catch (Exception e) {
606                            throw processException(e);
607                    }
608                    finally {
609                            closeSession(session);
610                    }
611    
612                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
613    
614                    if (isNew || !ReleaseModelImpl.COLUMN_BITMASK_ENABLED) {
615                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
616                    }
617    
618                    EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
619                            ReleaseImpl.class, release.getPrimaryKey(), release, false);
620    
621                    clearUniqueFindersCache(release);
622                    cacheUniqueFindersCache(release);
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.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.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)EntityCacheUtil.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                                            EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
718                                                    ReleaseImpl.class, primaryKey, _nullRelease);
719                                    }
720                            }
721                            catch (Exception e) {
722                                    EntityCacheUtil.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)EntityCacheUtil.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                                    EntityCacheUtil.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                    boolean pagination = true;
880                    FinderPath finderPath = null;
881                    Object[] finderArgs = null;
882    
883                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
884                                    (orderByComparator == null)) {
885                            pagination = false;
886                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
887                            finderArgs = FINDER_ARGS_EMPTY;
888                    }
889                    else {
890                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
891                            finderArgs = new Object[] { start, end, orderByComparator };
892                    }
893    
894                    List<Release> list = (List<Release>)FinderCacheUtil.getResult(finderPath,
895                                    finderArgs, this);
896    
897                    if (list == null) {
898                            StringBundler query = null;
899                            String sql = null;
900    
901                            if (orderByComparator != null) {
902                                    query = new StringBundler(2 +
903                                                    (orderByComparator.getOrderByFields().length * 3));
904    
905                                    query.append(_SQL_SELECT_RELEASE);
906    
907                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
908                                            orderByComparator);
909    
910                                    sql = query.toString();
911                            }
912                            else {
913                                    sql = _SQL_SELECT_RELEASE;
914    
915                                    if (pagination) {
916                                            sql = sql.concat(ReleaseModelImpl.ORDER_BY_JPQL);
917                                    }
918                            }
919    
920                            Session session = null;
921    
922                            try {
923                                    session = openSession();
924    
925                                    Query q = session.createQuery(sql);
926    
927                                    if (!pagination) {
928                                            list = (List<Release>)QueryUtil.list(q, getDialect(),
929                                                            start, end, false);
930    
931                                            Collections.sort(list);
932    
933                                            list = Collections.unmodifiableList(list);
934                                    }
935                                    else {
936                                            list = (List<Release>)QueryUtil.list(q, getDialect(),
937                                                            start, end);
938                                    }
939    
940                                    cacheResult(list);
941    
942                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
943                            }
944                            catch (Exception e) {
945                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
946    
947                                    throw processException(e);
948                            }
949                            finally {
950                                    closeSession(session);
951                            }
952                    }
953    
954                    return list;
955            }
956    
957            /**
958             * Removes all the releases from the database.
959             *
960             */
961            @Override
962            public void removeAll() {
963                    for (Release release : findAll()) {
964                            remove(release);
965                    }
966            }
967    
968            /**
969             * Returns the number of releases.
970             *
971             * @return the number of releases
972             */
973            @Override
974            public int countAll() {
975                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
976                                    FINDER_ARGS_EMPTY, this);
977    
978                    if (count == null) {
979                            Session session = null;
980    
981                            try {
982                                    session = openSession();
983    
984                                    Query q = session.createQuery(_SQL_COUNT_RELEASE);
985    
986                                    count = (Long)q.uniqueResult();
987    
988                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
989                                            FINDER_ARGS_EMPTY, count);
990                            }
991                            catch (Exception e) {
992                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
993                                            FINDER_ARGS_EMPTY);
994    
995                                    throw processException(e);
996                            }
997                            finally {
998                                    closeSession(session);
999                            }
1000                    }
1001    
1002                    return count.intValue();
1003            }
1004    
1005            @Override
1006            protected Set<String> getBadColumnNames() {
1007                    return _badColumnNames;
1008            }
1009    
1010            /**
1011             * Initializes the release persistence.
1012             */
1013            public void afterPropertiesSet() {
1014            }
1015    
1016            public void destroy() {
1017                    EntityCacheUtil.removeCache(ReleaseImpl.class.getName());
1018                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1019                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1020                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1021            }
1022    
1023            private static final String _SQL_SELECT_RELEASE = "SELECT release FROM Release release";
1024            private static final String _SQL_SELECT_RELEASE_WHERE_PKS_IN = "SELECT release FROM Release release WHERE releaseId IN (";
1025            private static final String _SQL_SELECT_RELEASE_WHERE = "SELECT release FROM Release release WHERE ";
1026            private static final String _SQL_COUNT_RELEASE = "SELECT COUNT(release) FROM Release release";
1027            private static final String _SQL_COUNT_RELEASE_WHERE = "SELECT COUNT(release) FROM Release release WHERE ";
1028            private static final String _ORDER_BY_ENTITY_ALIAS = "release.";
1029            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Release exists with the primary key ";
1030            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Release exists with the key {";
1031            private static final Log _log = LogFactoryUtil.getLog(ReleasePersistenceImpl.class);
1032            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1033                                    "state"
1034                            });
1035            private static final Release _nullRelease = new ReleaseImpl() {
1036                            @Override
1037                            public Object clone() {
1038                                    return this;
1039                            }
1040    
1041                            @Override
1042                            public CacheModel<Release> toCacheModel() {
1043                                    return _nullReleaseCacheModel;
1044                            }
1045                    };
1046    
1047            private static final CacheModel<Release> _nullReleaseCacheModel = new NullCacheModel();
1048    
1049            private static class NullCacheModel implements CacheModel<Release>,
1050                    MVCCModel {
1051                    @Override
1052                    public long getMvccVersion() {
1053                            return -1;
1054                    }
1055    
1056                    @Override
1057                    public void setMvccVersion(long mvccVersion) {
1058                    }
1059    
1060                    @Override
1061                    public Release toEntityModel() {
1062                            return _nullRelease;
1063                    }
1064            }
1065    }