001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchReleaseException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
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_FETCH_BY_SERVLETCONTEXTNAME = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
076                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
077                            FINDER_CLASS_NAME_ENTITY, "fetchByServletContextName",
078                            new String[] { String.class.getName() },
079                            ReleaseModelImpl.SERVLETCONTEXTNAME_COLUMN_BITMASK);
080            public static final FinderPath FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
081                            ReleaseModelImpl.FINDER_CACHE_ENABLED, Long.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
083                            "countByServletContextName", new String[] { String.class.getName() });
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
085                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
088                            ReleaseModelImpl.FINDER_CACHE_ENABLED, ReleaseImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
091                            ReleaseModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093    
094            /**
095             * Caches the release in the entity cache if it is enabled.
096             *
097             * @param release the release
098             */
099            public void cacheResult(Release release) {
100                    EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
101                            ReleaseImpl.class, release.getPrimaryKey(), release);
102    
103                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
104                            new Object[] { release.getServletContextName() }, release);
105    
106                    release.resetOriginalValues();
107            }
108    
109            /**
110             * Caches the releases in the entity cache if it is enabled.
111             *
112             * @param releases the releases
113             */
114            public void cacheResult(List<Release> releases) {
115                    for (Release release : releases) {
116                            if (EntityCacheUtil.getResult(
117                                                    ReleaseModelImpl.ENTITY_CACHE_ENABLED,
118                                                    ReleaseImpl.class, release.getPrimaryKey()) == null) {
119                                    cacheResult(release);
120                            }
121                            else {
122                                    release.resetOriginalValues();
123                            }
124                    }
125            }
126    
127            /**
128             * Clears the cache for all releases.
129             *
130             * <p>
131             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
132             * </p>
133             */
134            @Override
135            public void clearCache() {
136                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
137                            CacheRegistryUtil.clear(ReleaseImpl.class.getName());
138                    }
139    
140                    EntityCacheUtil.clearCache(ReleaseImpl.class.getName());
141    
142                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
143                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
144                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
145            }
146    
147            /**
148             * Clears the cache for the release.
149             *
150             * <p>
151             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
152             * </p>
153             */
154            @Override
155            public void clearCache(Release release) {
156                    EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
157                            ReleaseImpl.class, release.getPrimaryKey());
158    
159                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
160                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
161    
162                    clearUniqueFindersCache(release);
163            }
164    
165            @Override
166            public void clearCache(List<Release> releases) {
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
169    
170                    for (Release release : releases) {
171                            EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
172                                    ReleaseImpl.class, release.getPrimaryKey());
173    
174                            clearUniqueFindersCache(release);
175                    }
176            }
177    
178            protected void cacheUniqueFindersCache(Release release) {
179                    if (release.isNew()) {
180                            Object[] args = new Object[] { release.getServletContextName() };
181    
182                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
183                                    args, Long.valueOf(1));
184                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
185                                    args, release);
186                    }
187                    else {
188                            ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl)release;
189    
190                            if ((releaseModelImpl.getColumnBitmask() &
191                                            FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) {
192                                    Object[] args = new Object[] { release.getServletContextName() };
193    
194                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
195                                            args, Long.valueOf(1));
196                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
197                                            args, release);
198                            }
199                    }
200            }
201    
202            protected void clearUniqueFindersCache(Release release) {
203                    ReleaseModelImpl releaseModelImpl = (ReleaseModelImpl)release;
204    
205                    Object[] args = new Object[] { release.getServletContextName() };
206    
207                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
208                            args);
209                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
210                            args);
211    
212                    if ((releaseModelImpl.getColumnBitmask() &
213                                    FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME.getColumnBitmask()) != 0) {
214                            args = new Object[] { releaseModelImpl.getOriginalServletContextName() };
215    
216                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
217                                    args);
218                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
219                                    args);
220                    }
221            }
222    
223            /**
224             * Creates a new release with the primary key. Does not add the release to the database.
225             *
226             * @param releaseId the primary key for the new release
227             * @return the new release
228             */
229            public Release create(long releaseId) {
230                    Release release = new ReleaseImpl();
231    
232                    release.setNew(true);
233                    release.setPrimaryKey(releaseId);
234    
235                    return release;
236            }
237    
238            /**
239             * Removes the release with the primary key from the database. Also notifies the appropriate model listeners.
240             *
241             * @param releaseId the primary key of the release
242             * @return the release that was removed
243             * @throws com.liferay.portal.NoSuchReleaseException if a release with the primary key could not be found
244             * @throws SystemException if a system exception occurred
245             */
246            public Release remove(long releaseId)
247                    throws NoSuchReleaseException, SystemException {
248                    return remove(Long.valueOf(releaseId));
249            }
250    
251            /**
252             * Removes the release with the primary key from the database. Also notifies the appropriate model listeners.
253             *
254             * @param primaryKey the primary key of the release
255             * @return the release that was removed
256             * @throws com.liferay.portal.NoSuchReleaseException if a release with the primary key could not be found
257             * @throws SystemException if a system exception occurred
258             */
259            @Override
260            public Release remove(Serializable primaryKey)
261                    throws NoSuchReleaseException, SystemException {
262                    Session session = null;
263    
264                    try {
265                            session = openSession();
266    
267                            Release release = (Release)session.get(ReleaseImpl.class, primaryKey);
268    
269                            if (release == null) {
270                                    if (_log.isWarnEnabled()) {
271                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
272                                    }
273    
274                                    throw new NoSuchReleaseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
275                                            primaryKey);
276                            }
277    
278                            return remove(release);
279                    }
280                    catch (NoSuchReleaseException nsee) {
281                            throw nsee;
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            closeSession(session);
288                    }
289            }
290    
291            @Override
292            protected Release removeImpl(Release release) throws SystemException {
293                    release = toUnwrappedModel(release);
294    
295                    Session session = null;
296    
297                    try {
298                            session = openSession();
299    
300                            BatchSessionUtil.delete(session, release);
301                    }
302                    catch (Exception e) {
303                            throw processException(e);
304                    }
305                    finally {
306                            closeSession(session);
307                    }
308    
309                    clearCache(release);
310    
311                    return release;
312            }
313    
314            @Override
315            public Release updateImpl(com.liferay.portal.model.Release release,
316                    boolean merge) throws SystemException {
317                    release = toUnwrappedModel(release);
318    
319                    boolean isNew = release.isNew();
320    
321                    Session session = null;
322    
323                    try {
324                            session = openSession();
325    
326                            BatchSessionUtil.update(session, release, merge);
327    
328                            release.setNew(false);
329                    }
330                    catch (Exception e) {
331                            throw processException(e);
332                    }
333                    finally {
334                            closeSession(session);
335                    }
336    
337                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
338    
339                    if (isNew || !ReleaseModelImpl.COLUMN_BITMASK_ENABLED) {
340                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
341                    }
342    
343                    EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
344                            ReleaseImpl.class, release.getPrimaryKey(), release);
345    
346                    clearUniqueFindersCache(release);
347                    cacheUniqueFindersCache(release);
348    
349                    return release;
350            }
351    
352            protected Release toUnwrappedModel(Release release) {
353                    if (release instanceof ReleaseImpl) {
354                            return release;
355                    }
356    
357                    ReleaseImpl releaseImpl = new ReleaseImpl();
358    
359                    releaseImpl.setNew(release.isNew());
360                    releaseImpl.setPrimaryKey(release.getPrimaryKey());
361    
362                    releaseImpl.setReleaseId(release.getReleaseId());
363                    releaseImpl.setCreateDate(release.getCreateDate());
364                    releaseImpl.setModifiedDate(release.getModifiedDate());
365                    releaseImpl.setServletContextName(release.getServletContextName());
366                    releaseImpl.setBuildNumber(release.getBuildNumber());
367                    releaseImpl.setBuildDate(release.getBuildDate());
368                    releaseImpl.setVerified(release.isVerified());
369                    releaseImpl.setState(release.getState());
370                    releaseImpl.setTestString(release.getTestString());
371    
372                    return releaseImpl;
373            }
374    
375            /**
376             * Returns the release with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
377             *
378             * @param primaryKey the primary key of the release
379             * @return the release
380             * @throws com.liferay.portal.NoSuchModelException if a release with the primary key could not be found
381             * @throws SystemException if a system exception occurred
382             */
383            @Override
384            public Release findByPrimaryKey(Serializable primaryKey)
385                    throws NoSuchModelException, SystemException {
386                    return findByPrimaryKey(((Long)primaryKey).longValue());
387            }
388    
389            /**
390             * Returns the release with the primary key or throws a {@link com.liferay.portal.NoSuchReleaseException} if it could not be found.
391             *
392             * @param releaseId the primary key of the release
393             * @return the release
394             * @throws com.liferay.portal.NoSuchReleaseException if a release with the primary key could not be found
395             * @throws SystemException if a system exception occurred
396             */
397            public Release findByPrimaryKey(long releaseId)
398                    throws NoSuchReleaseException, SystemException {
399                    Release release = fetchByPrimaryKey(releaseId);
400    
401                    if (release == null) {
402                            if (_log.isWarnEnabled()) {
403                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + releaseId);
404                            }
405    
406                            throw new NoSuchReleaseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
407                                    releaseId);
408                    }
409    
410                    return release;
411            }
412    
413            /**
414             * Returns the release with the primary key or returns <code>null</code> if it could not be found.
415             *
416             * @param primaryKey the primary key of the release
417             * @return the release, or <code>null</code> if a release with the primary key could not be found
418             * @throws SystemException if a system exception occurred
419             */
420            @Override
421            public Release fetchByPrimaryKey(Serializable primaryKey)
422                    throws SystemException {
423                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
424            }
425    
426            /**
427             * Returns the release with the primary key or returns <code>null</code> if it could not be found.
428             *
429             * @param releaseId the primary key of the release
430             * @return the release, or <code>null</code> if a release with the primary key could not be found
431             * @throws SystemException if a system exception occurred
432             */
433            public Release fetchByPrimaryKey(long releaseId) throws SystemException {
434                    Release release = (Release)EntityCacheUtil.getResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
435                                    ReleaseImpl.class, releaseId);
436    
437                    if (release == _nullRelease) {
438                            return null;
439                    }
440    
441                    if (release == null) {
442                            Session session = null;
443    
444                            boolean hasException = false;
445    
446                            try {
447                                    session = openSession();
448    
449                                    release = (Release)session.get(ReleaseImpl.class,
450                                                    Long.valueOf(releaseId));
451                            }
452                            catch (Exception e) {
453                                    hasException = true;
454    
455                                    throw processException(e);
456                            }
457                            finally {
458                                    if (release != null) {
459                                            cacheResult(release);
460                                    }
461                                    else if (!hasException) {
462                                            EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
463                                                    ReleaseImpl.class, releaseId, _nullRelease);
464                                    }
465    
466                                    closeSession(session);
467                            }
468                    }
469    
470                    return release;
471            }
472    
473            /**
474             * Returns the release where servletContextName = &#63; or throws a {@link com.liferay.portal.NoSuchReleaseException} if it could not be found.
475             *
476             * @param servletContextName the servlet context name
477             * @return the matching release
478             * @throws com.liferay.portal.NoSuchReleaseException if a matching release could not be found
479             * @throws SystemException if a system exception occurred
480             */
481            public Release findByServletContextName(String servletContextName)
482                    throws NoSuchReleaseException, SystemException {
483                    Release release = fetchByServletContextName(servletContextName);
484    
485                    if (release == null) {
486                            StringBundler msg = new StringBundler(4);
487    
488                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
489    
490                            msg.append("servletContextName=");
491                            msg.append(servletContextName);
492    
493                            msg.append(StringPool.CLOSE_CURLY_BRACE);
494    
495                            if (_log.isWarnEnabled()) {
496                                    _log.warn(msg.toString());
497                            }
498    
499                            throw new NoSuchReleaseException(msg.toString());
500                    }
501    
502                    return release;
503            }
504    
505            /**
506             * Returns the release where servletContextName = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
507             *
508             * @param servletContextName the servlet context name
509             * @return the matching release, or <code>null</code> if a matching release could not be found
510             * @throws SystemException if a system exception occurred
511             */
512            public Release fetchByServletContextName(String servletContextName)
513                    throws SystemException {
514                    return fetchByServletContextName(servletContextName, true);
515            }
516    
517            /**
518             * Returns the release where servletContextName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
519             *
520             * @param servletContextName the servlet context name
521             * @param retrieveFromCache whether to use the finder cache
522             * @return the matching release, or <code>null</code> if a matching release could not be found
523             * @throws SystemException if a system exception occurred
524             */
525            public Release fetchByServletContextName(String servletContextName,
526                    boolean retrieveFromCache) throws SystemException {
527                    Object[] finderArgs = new Object[] { servletContextName };
528    
529                    Object result = null;
530    
531                    if (retrieveFromCache) {
532                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
533                                            finderArgs, this);
534                    }
535    
536                    if (result instanceof Release) {
537                            Release release = (Release)result;
538    
539                            if (!Validator.equals(servletContextName,
540                                                    release.getServletContextName())) {
541                                    result = null;
542                            }
543                    }
544    
545                    if (result == null) {
546                            StringBundler query = new StringBundler(2);
547    
548                            query.append(_SQL_SELECT_RELEASE_WHERE);
549    
550                            if (servletContextName == null) {
551                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
552                            }
553                            else {
554                                    if (servletContextName.equals(StringPool.BLANK)) {
555                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
556                                    }
557                                    else {
558                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
559                                    }
560                            }
561    
562                            String sql = query.toString();
563    
564                            Session session = null;
565    
566                            try {
567                                    session = openSession();
568    
569                                    Query q = session.createQuery(sql);
570    
571                                    QueryPos qPos = QueryPos.getInstance(q);
572    
573                                    if (servletContextName != null) {
574                                            qPos.add(servletContextName);
575                                    }
576    
577                                    List<Release> list = q.list();
578    
579                                    result = list;
580    
581                                    Release release = null;
582    
583                                    if (list.isEmpty()) {
584                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
585                                                    finderArgs, list);
586                                    }
587                                    else {
588                                            release = list.get(0);
589    
590                                            cacheResult(release);
591    
592                                            if ((release.getServletContextName() == null) ||
593                                                            !release.getServletContextName()
594                                                                                    .equals(servletContextName)) {
595                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
596                                                            finderArgs, release);
597                                            }
598                                    }
599    
600                                    return release;
601                            }
602                            catch (Exception e) {
603                                    throw processException(e);
604                            }
605                            finally {
606                                    if (result == null) {
607                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
608                                                    finderArgs);
609                                    }
610    
611                                    closeSession(session);
612                            }
613                    }
614                    else {
615                            if (result instanceof List<?>) {
616                                    return null;
617                            }
618                            else {
619                                    return (Release)result;
620                            }
621                    }
622            }
623    
624            /**
625             * Returns all the releases.
626             *
627             * @return the releases
628             * @throws SystemException if a system exception occurred
629             */
630            public List<Release> findAll() throws SystemException {
631                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
632            }
633    
634            /**
635             * Returns a range of all the releases.
636             *
637             * <p>
638             * 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.
639             * </p>
640             *
641             * @param start the lower bound of the range of releases
642             * @param end the upper bound of the range of releases (not inclusive)
643             * @return the range of releases
644             * @throws SystemException if a system exception occurred
645             */
646            public List<Release> findAll(int start, int end) throws SystemException {
647                    return findAll(start, end, null);
648            }
649    
650            /**
651             * Returns an ordered range of all the releases.
652             *
653             * <p>
654             * 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.
655             * </p>
656             *
657             * @param start the lower bound of the range of releases
658             * @param end the upper bound of the range of releases (not inclusive)
659             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
660             * @return the ordered range of releases
661             * @throws SystemException if a system exception occurred
662             */
663            public List<Release> findAll(int start, int end,
664                    OrderByComparator orderByComparator) throws SystemException {
665                    FinderPath finderPath = null;
666                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
667    
668                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
669                                    (orderByComparator == null)) {
670                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
671                            finderArgs = FINDER_ARGS_EMPTY;
672                    }
673                    else {
674                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
675                            finderArgs = new Object[] { start, end, orderByComparator };
676                    }
677    
678                    List<Release> list = (List<Release>)FinderCacheUtil.getResult(finderPath,
679                                    finderArgs, this);
680    
681                    if (list == null) {
682                            StringBundler query = null;
683                            String sql = null;
684    
685                            if (orderByComparator != null) {
686                                    query = new StringBundler(2 +
687                                                    (orderByComparator.getOrderByFields().length * 3));
688    
689                                    query.append(_SQL_SELECT_RELEASE);
690    
691                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
692                                            orderByComparator);
693    
694                                    sql = query.toString();
695                            }
696                            else {
697                                    sql = _SQL_SELECT_RELEASE;
698                            }
699    
700                            Session session = null;
701    
702                            try {
703                                    session = openSession();
704    
705                                    Query q = session.createQuery(sql);
706    
707                                    if (orderByComparator == null) {
708                                            list = (List<Release>)QueryUtil.list(q, getDialect(),
709                                                            start, end, false);
710    
711                                            Collections.sort(list);
712                                    }
713                                    else {
714                                            list = (List<Release>)QueryUtil.list(q, getDialect(),
715                                                            start, end);
716                                    }
717                            }
718                            catch (Exception e) {
719                                    throw processException(e);
720                            }
721                            finally {
722                                    if (list == null) {
723                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
724                                    }
725                                    else {
726                                            cacheResult(list);
727    
728                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
729                                    }
730    
731                                    closeSession(session);
732                            }
733                    }
734    
735                    return list;
736            }
737    
738            /**
739             * Removes the release where servletContextName = &#63; from the database.
740             *
741             * @param servletContextName the servlet context name
742             * @return the release that was removed
743             * @throws SystemException if a system exception occurred
744             */
745            public Release removeByServletContextName(String servletContextName)
746                    throws NoSuchReleaseException, SystemException {
747                    Release release = findByServletContextName(servletContextName);
748    
749                    return remove(release);
750            }
751    
752            /**
753             * Removes all the releases from the database.
754             *
755             * @throws SystemException if a system exception occurred
756             */
757            public void removeAll() throws SystemException {
758                    for (Release release : findAll()) {
759                            remove(release);
760                    }
761            }
762    
763            /**
764             * Returns the number of releases where servletContextName = &#63;.
765             *
766             * @param servletContextName the servlet context name
767             * @return the number of matching releases
768             * @throws SystemException if a system exception occurred
769             */
770            public int countByServletContextName(String servletContextName)
771                    throws SystemException {
772                    Object[] finderArgs = new Object[] { servletContextName };
773    
774                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
775                                    finderArgs, this);
776    
777                    if (count == null) {
778                            StringBundler query = new StringBundler(2);
779    
780                            query.append(_SQL_COUNT_RELEASE_WHERE);
781    
782                            if (servletContextName == null) {
783                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
784                            }
785                            else {
786                                    if (servletContextName.equals(StringPool.BLANK)) {
787                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
788                                    }
789                                    else {
790                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
791                                    }
792                            }
793    
794                            String sql = query.toString();
795    
796                            Session session = null;
797    
798                            try {
799                                    session = openSession();
800    
801                                    Query q = session.createQuery(sql);
802    
803                                    QueryPos qPos = QueryPos.getInstance(q);
804    
805                                    if (servletContextName != null) {
806                                            qPos.add(servletContextName);
807                                    }
808    
809                                    count = (Long)q.uniqueResult();
810                            }
811                            catch (Exception e) {
812                                    throw processException(e);
813                            }
814                            finally {
815                                    if (count == null) {
816                                            count = Long.valueOf(0);
817                                    }
818    
819                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
820                                            finderArgs, count);
821    
822                                    closeSession(session);
823                            }
824                    }
825    
826                    return count.intValue();
827            }
828    
829            /**
830             * Returns the number of releases.
831             *
832             * @return the number of releases
833             * @throws SystemException if a system exception occurred
834             */
835            public int countAll() throws SystemException {
836                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
837                                    FINDER_ARGS_EMPTY, this);
838    
839                    if (count == null) {
840                            Session session = null;
841    
842                            try {
843                                    session = openSession();
844    
845                                    Query q = session.createQuery(_SQL_COUNT_RELEASE);
846    
847                                    count = (Long)q.uniqueResult();
848                            }
849                            catch (Exception e) {
850                                    throw processException(e);
851                            }
852                            finally {
853                                    if (count == null) {
854                                            count = Long.valueOf(0);
855                                    }
856    
857                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
858                                            FINDER_ARGS_EMPTY, count);
859    
860                                    closeSession(session);
861                            }
862                    }
863    
864                    return count.intValue();
865            }
866    
867            /**
868             * Initializes the release persistence.
869             */
870            public void afterPropertiesSet() {
871                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
872                                            com.liferay.portal.util.PropsUtil.get(
873                                                    "value.object.listener.com.liferay.portal.model.Release")));
874    
875                    if (listenerClassNames.length > 0) {
876                            try {
877                                    List<ModelListener<Release>> listenersList = new ArrayList<ModelListener<Release>>();
878    
879                                    for (String listenerClassName : listenerClassNames) {
880                                            Class<?> clazz = getClass();
881    
882                                            listenersList.add((ModelListener<Release>)InstanceFactory.newInstance(
883                                                            clazz.getClassLoader(), listenerClassName));
884                                    }
885    
886                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
887                            }
888                            catch (Exception e) {
889                                    _log.error(e);
890                            }
891                    }
892            }
893    
894            public void destroy() {
895                    EntityCacheUtil.removeCache(ReleaseImpl.class.getName());
896                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
897                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
898            }
899    
900            @BeanReference(type = AccountPersistence.class)
901            protected AccountPersistence accountPersistence;
902            @BeanReference(type = AddressPersistence.class)
903            protected AddressPersistence addressPersistence;
904            @BeanReference(type = BrowserTrackerPersistence.class)
905            protected BrowserTrackerPersistence browserTrackerPersistence;
906            @BeanReference(type = ClassNamePersistence.class)
907            protected ClassNamePersistence classNamePersistence;
908            @BeanReference(type = ClusterGroupPersistence.class)
909            protected ClusterGroupPersistence clusterGroupPersistence;
910            @BeanReference(type = CompanyPersistence.class)
911            protected CompanyPersistence companyPersistence;
912            @BeanReference(type = ContactPersistence.class)
913            protected ContactPersistence contactPersistence;
914            @BeanReference(type = CountryPersistence.class)
915            protected CountryPersistence countryPersistence;
916            @BeanReference(type = EmailAddressPersistence.class)
917            protected EmailAddressPersistence emailAddressPersistence;
918            @BeanReference(type = GroupPersistence.class)
919            protected GroupPersistence groupPersistence;
920            @BeanReference(type = ImagePersistence.class)
921            protected ImagePersistence imagePersistence;
922            @BeanReference(type = LayoutPersistence.class)
923            protected LayoutPersistence layoutPersistence;
924            @BeanReference(type = LayoutBranchPersistence.class)
925            protected LayoutBranchPersistence layoutBranchPersistence;
926            @BeanReference(type = LayoutPrototypePersistence.class)
927            protected LayoutPrototypePersistence layoutPrototypePersistence;
928            @BeanReference(type = LayoutRevisionPersistence.class)
929            protected LayoutRevisionPersistence layoutRevisionPersistence;
930            @BeanReference(type = LayoutSetPersistence.class)
931            protected LayoutSetPersistence layoutSetPersistence;
932            @BeanReference(type = LayoutSetBranchPersistence.class)
933            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
934            @BeanReference(type = LayoutSetPrototypePersistence.class)
935            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
936            @BeanReference(type = ListTypePersistence.class)
937            protected ListTypePersistence listTypePersistence;
938            @BeanReference(type = LockPersistence.class)
939            protected LockPersistence lockPersistence;
940            @BeanReference(type = MembershipRequestPersistence.class)
941            protected MembershipRequestPersistence membershipRequestPersistence;
942            @BeanReference(type = OrganizationPersistence.class)
943            protected OrganizationPersistence organizationPersistence;
944            @BeanReference(type = OrgGroupPermissionPersistence.class)
945            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
946            @BeanReference(type = OrgGroupRolePersistence.class)
947            protected OrgGroupRolePersistence orgGroupRolePersistence;
948            @BeanReference(type = OrgLaborPersistence.class)
949            protected OrgLaborPersistence orgLaborPersistence;
950            @BeanReference(type = PasswordPolicyPersistence.class)
951            protected PasswordPolicyPersistence passwordPolicyPersistence;
952            @BeanReference(type = PasswordPolicyRelPersistence.class)
953            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
954            @BeanReference(type = PasswordTrackerPersistence.class)
955            protected PasswordTrackerPersistence passwordTrackerPersistence;
956            @BeanReference(type = PermissionPersistence.class)
957            protected PermissionPersistence permissionPersistence;
958            @BeanReference(type = PhonePersistence.class)
959            protected PhonePersistence phonePersistence;
960            @BeanReference(type = PluginSettingPersistence.class)
961            protected PluginSettingPersistence pluginSettingPersistence;
962            @BeanReference(type = PortalPreferencesPersistence.class)
963            protected PortalPreferencesPersistence portalPreferencesPersistence;
964            @BeanReference(type = PortletPersistence.class)
965            protected PortletPersistence portletPersistence;
966            @BeanReference(type = PortletItemPersistence.class)
967            protected PortletItemPersistence portletItemPersistence;
968            @BeanReference(type = PortletPreferencesPersistence.class)
969            protected PortletPreferencesPersistence portletPreferencesPersistence;
970            @BeanReference(type = RegionPersistence.class)
971            protected RegionPersistence regionPersistence;
972            @BeanReference(type = ReleasePersistence.class)
973            protected ReleasePersistence releasePersistence;
974            @BeanReference(type = RepositoryPersistence.class)
975            protected RepositoryPersistence repositoryPersistence;
976            @BeanReference(type = RepositoryEntryPersistence.class)
977            protected RepositoryEntryPersistence repositoryEntryPersistence;
978            @BeanReference(type = ResourcePersistence.class)
979            protected ResourcePersistence resourcePersistence;
980            @BeanReference(type = ResourceActionPersistence.class)
981            protected ResourceActionPersistence resourceActionPersistence;
982            @BeanReference(type = ResourceBlockPersistence.class)
983            protected ResourceBlockPersistence resourceBlockPersistence;
984            @BeanReference(type = ResourceBlockPermissionPersistence.class)
985            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
986            @BeanReference(type = ResourceCodePersistence.class)
987            protected ResourceCodePersistence resourceCodePersistence;
988            @BeanReference(type = ResourcePermissionPersistence.class)
989            protected ResourcePermissionPersistence resourcePermissionPersistence;
990            @BeanReference(type = ResourceTypePermissionPersistence.class)
991            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
992            @BeanReference(type = RolePersistence.class)
993            protected RolePersistence rolePersistence;
994            @BeanReference(type = ServiceComponentPersistence.class)
995            protected ServiceComponentPersistence serviceComponentPersistence;
996            @BeanReference(type = ShardPersistence.class)
997            protected ShardPersistence shardPersistence;
998            @BeanReference(type = SubscriptionPersistence.class)
999            protected SubscriptionPersistence subscriptionPersistence;
1000            @BeanReference(type = TeamPersistence.class)
1001            protected TeamPersistence teamPersistence;
1002            @BeanReference(type = TicketPersistence.class)
1003            protected TicketPersistence ticketPersistence;
1004            @BeanReference(type = UserPersistence.class)
1005            protected UserPersistence userPersistence;
1006            @BeanReference(type = UserGroupPersistence.class)
1007            protected UserGroupPersistence userGroupPersistence;
1008            @BeanReference(type = UserGroupGroupRolePersistence.class)
1009            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1010            @BeanReference(type = UserGroupRolePersistence.class)
1011            protected UserGroupRolePersistence userGroupRolePersistence;
1012            @BeanReference(type = UserIdMapperPersistence.class)
1013            protected UserIdMapperPersistence userIdMapperPersistence;
1014            @BeanReference(type = UserNotificationEventPersistence.class)
1015            protected UserNotificationEventPersistence userNotificationEventPersistence;
1016            @BeanReference(type = UserTrackerPersistence.class)
1017            protected UserTrackerPersistence userTrackerPersistence;
1018            @BeanReference(type = UserTrackerPathPersistence.class)
1019            protected UserTrackerPathPersistence userTrackerPathPersistence;
1020            @BeanReference(type = VirtualHostPersistence.class)
1021            protected VirtualHostPersistence virtualHostPersistence;
1022            @BeanReference(type = WebDAVPropsPersistence.class)
1023            protected WebDAVPropsPersistence webDAVPropsPersistence;
1024            @BeanReference(type = WebsitePersistence.class)
1025            protected WebsitePersistence websitePersistence;
1026            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1027            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1028            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1029            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1030            private static final String _SQL_SELECT_RELEASE = "SELECT release FROM Release release";
1031            private static final String _SQL_SELECT_RELEASE_WHERE = "SELECT release FROM Release release WHERE ";
1032            private static final String _SQL_COUNT_RELEASE = "SELECT COUNT(release) FROM Release release";
1033            private static final String _SQL_COUNT_RELEASE_WHERE = "SELECT COUNT(release) FROM Release release WHERE ";
1034            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1 =
1035                    "release.servletContextName IS NULL";
1036            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2 =
1037                    "lower(release.servletContextName) = lower(CAST_TEXT(?))";
1038            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3 =
1039                    "(release.servletContextName IS NULL OR lower(release.servletContextName) = lower(CAST_TEXT(?)))";
1040            private static final String _ORDER_BY_ENTITY_ALIAS = "release.";
1041            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Release exists with the primary key ";
1042            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Release exists with the key {";
1043            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1044            private static Log _log = LogFactoryUtil.getLog(ReleasePersistenceImpl.class);
1045            private static Release _nullRelease = new ReleaseImpl() {
1046                            @Override
1047                            public Object clone() {
1048                                    return this;
1049                            }
1050    
1051                            @Override
1052                            public CacheModel<Release> toCacheModel() {
1053                                    return _nullReleaseCacheModel;
1054                            }
1055                    };
1056    
1057            private static CacheModel<Release> _nullReleaseCacheModel = new CacheModel<Release>() {
1058                            public Release toEntityModel() {
1059                                    return _nullRelease;
1060                            }
1061                    };
1062    }