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