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