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