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