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