001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.getOriginalServletContextName() });
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                            Session session = null;
455    
456                            try {
457                                    session = openSession();
458    
459                                    StringBundler query = new StringBundler(2);
460    
461                                    query.append(_SQL_SELECT_RELEASE_WHERE);
462    
463                                    if (servletContextName == null) {
464                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
465                                    }
466                                    else {
467                                            if (servletContextName.equals(StringPool.BLANK)) {
468                                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
469                                            }
470                                            else {
471                                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
472                                            }
473                                    }
474    
475                                    String sql = query.toString();
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.putResult(FINDER_PATH_FETCH_BY_SERVLETCONTEXTNAME,
516                                                    finderArgs, new ArrayList<Release>());
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                            Session session = null;
583    
584                            try {
585                                    session = openSession();
586    
587                                    StringBundler query = null;
588                                    String sql = null;
589    
590                                    if (orderByComparator != null) {
591                                            query = new StringBundler(2 +
592                                                            (orderByComparator.getOrderByFields().length * 3));
593    
594                                            query.append(_SQL_SELECT_RELEASE);
595    
596                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
597                                                    orderByComparator);
598    
599                                            sql = query.toString();
600                                    }
601                                    else {
602                                            sql = _SQL_SELECT_RELEASE;
603                                    }
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                                            list = new ArrayList<Release>();
624                                    }
625    
626                                    cacheResult(list);
627    
628                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
629    
630                                    closeSession(session);
631                            }
632                    }
633    
634                    return list;
635            }
636    
637            /**
638             * Removes the release where servletContextName = &#63; from the database.
639             *
640             * @param servletContextName the servlet context name to search with
641             * @throws SystemException if a system exception occurred
642             */
643            public void removeByServletContextName(String servletContextName)
644                    throws NoSuchReleaseException, SystemException {
645                    Release release = findByServletContextName(servletContextName);
646    
647                    remove(release);
648            }
649    
650            /**
651             * Removes all the releases from the database.
652             *
653             * @throws SystemException if a system exception occurred
654             */
655            public void removeAll() throws SystemException {
656                    for (Release release : findAll()) {
657                            remove(release);
658                    }
659            }
660    
661            /**
662             * Counts all the releases where servletContextName = &#63;.
663             *
664             * @param servletContextName the servlet context name to search with
665             * @return the number of matching releases
666             * @throws SystemException if a system exception occurred
667             */
668            public int countByServletContextName(String servletContextName)
669                    throws SystemException {
670                    Object[] finderArgs = new Object[] { servletContextName };
671    
672                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
673                                    finderArgs, this);
674    
675                    if (count == null) {
676                            Session session = null;
677    
678                            try {
679                                    session = openSession();
680    
681                                    StringBundler query = new StringBundler(2);
682    
683                                    query.append(_SQL_COUNT_RELEASE_WHERE);
684    
685                                    if (servletContextName == null) {
686                                            query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1);
687                                    }
688                                    else {
689                                            if (servletContextName.equals(StringPool.BLANK)) {
690                                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3);
691                                            }
692                                            else {
693                                                    query.append(_FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2);
694                                            }
695                                    }
696    
697                                    String sql = query.toString();
698    
699                                    Query q = session.createQuery(sql);
700    
701                                    QueryPos qPos = QueryPos.getInstance(q);
702    
703                                    if (servletContextName != null) {
704                                            qPos.add(servletContextName);
705                                    }
706    
707                                    count = (Long)q.uniqueResult();
708                            }
709                            catch (Exception e) {
710                                    throw processException(e);
711                            }
712                            finally {
713                                    if (count == null) {
714                                            count = Long.valueOf(0);
715                                    }
716    
717                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVLETCONTEXTNAME,
718                                            finderArgs, count);
719    
720                                    closeSession(session);
721                            }
722                    }
723    
724                    return count.intValue();
725            }
726    
727            /**
728             * Counts all the releases.
729             *
730             * @return the number of releases
731             * @throws SystemException if a system exception occurred
732             */
733            public int countAll() throws SystemException {
734                    Object[] finderArgs = new Object[0];
735    
736                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
737                                    finderArgs, this);
738    
739                    if (count == null) {
740                            Session session = null;
741    
742                            try {
743                                    session = openSession();
744    
745                                    Query q = session.createQuery(_SQL_COUNT_RELEASE);
746    
747                                    count = (Long)q.uniqueResult();
748                            }
749                            catch (Exception e) {
750                                    throw processException(e);
751                            }
752                            finally {
753                                    if (count == null) {
754                                            count = Long.valueOf(0);
755                                    }
756    
757                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
758                                            count);
759    
760                                    closeSession(session);
761                            }
762                    }
763    
764                    return count.intValue();
765            }
766    
767            /**
768             * Initializes the release persistence.
769             */
770            public void afterPropertiesSet() {
771                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
772                                            com.liferay.portal.util.PropsUtil.get(
773                                                    "value.object.listener.com.liferay.portal.model.Release")));
774    
775                    if (listenerClassNames.length > 0) {
776                            try {
777                                    List<ModelListener<Release>> listenersList = new ArrayList<ModelListener<Release>>();
778    
779                                    for (String listenerClassName : listenerClassNames) {
780                                            listenersList.add((ModelListener<Release>)InstanceFactory.newInstance(
781                                                            listenerClassName));
782                                    }
783    
784                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
785                            }
786                            catch (Exception e) {
787                                    _log.error(e);
788                            }
789                    }
790            }
791    
792            public void destroy() {
793                    EntityCacheUtil.removeCache(ReleaseImpl.class.getName());
794                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
795                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
796            }
797    
798            @BeanReference(type = AccountPersistence.class)
799            protected AccountPersistence accountPersistence;
800            @BeanReference(type = AddressPersistence.class)
801            protected AddressPersistence addressPersistence;
802            @BeanReference(type = BrowserTrackerPersistence.class)
803            protected BrowserTrackerPersistence browserTrackerPersistence;
804            @BeanReference(type = ClassNamePersistence.class)
805            protected ClassNamePersistence classNamePersistence;
806            @BeanReference(type = ClusterGroupPersistence.class)
807            protected ClusterGroupPersistence clusterGroupPersistence;
808            @BeanReference(type = CompanyPersistence.class)
809            protected CompanyPersistence companyPersistence;
810            @BeanReference(type = ContactPersistence.class)
811            protected ContactPersistence contactPersistence;
812            @BeanReference(type = CountryPersistence.class)
813            protected CountryPersistence countryPersistence;
814            @BeanReference(type = EmailAddressPersistence.class)
815            protected EmailAddressPersistence emailAddressPersistence;
816            @BeanReference(type = GroupPersistence.class)
817            protected GroupPersistence groupPersistence;
818            @BeanReference(type = ImagePersistence.class)
819            protected ImagePersistence imagePersistence;
820            @BeanReference(type = LayoutPersistence.class)
821            protected LayoutPersistence layoutPersistence;
822            @BeanReference(type = LayoutPrototypePersistence.class)
823            protected LayoutPrototypePersistence layoutPrototypePersistence;
824            @BeanReference(type = LayoutSetPersistence.class)
825            protected LayoutSetPersistence layoutSetPersistence;
826            @BeanReference(type = LayoutSetPrototypePersistence.class)
827            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
828            @BeanReference(type = ListTypePersistence.class)
829            protected ListTypePersistence listTypePersistence;
830            @BeanReference(type = LockPersistence.class)
831            protected LockPersistence lockPersistence;
832            @BeanReference(type = MembershipRequestPersistence.class)
833            protected MembershipRequestPersistence membershipRequestPersistence;
834            @BeanReference(type = OrganizationPersistence.class)
835            protected OrganizationPersistence organizationPersistence;
836            @BeanReference(type = OrgGroupPermissionPersistence.class)
837            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
838            @BeanReference(type = OrgGroupRolePersistence.class)
839            protected OrgGroupRolePersistence orgGroupRolePersistence;
840            @BeanReference(type = OrgLaborPersistence.class)
841            protected OrgLaborPersistence orgLaborPersistence;
842            @BeanReference(type = PasswordPolicyPersistence.class)
843            protected PasswordPolicyPersistence passwordPolicyPersistence;
844            @BeanReference(type = PasswordPolicyRelPersistence.class)
845            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
846            @BeanReference(type = PasswordTrackerPersistence.class)
847            protected PasswordTrackerPersistence passwordTrackerPersistence;
848            @BeanReference(type = PermissionPersistence.class)
849            protected PermissionPersistence permissionPersistence;
850            @BeanReference(type = PhonePersistence.class)
851            protected PhonePersistence phonePersistence;
852            @BeanReference(type = PluginSettingPersistence.class)
853            protected PluginSettingPersistence pluginSettingPersistence;
854            @BeanReference(type = PortletPersistence.class)
855            protected PortletPersistence portletPersistence;
856            @BeanReference(type = PortletItemPersistence.class)
857            protected PortletItemPersistence portletItemPersistence;
858            @BeanReference(type = PortletPreferencesPersistence.class)
859            protected PortletPreferencesPersistence portletPreferencesPersistence;
860            @BeanReference(type = RegionPersistence.class)
861            protected RegionPersistence regionPersistence;
862            @BeanReference(type = ReleasePersistence.class)
863            protected ReleasePersistence releasePersistence;
864            @BeanReference(type = ResourcePersistence.class)
865            protected ResourcePersistence resourcePersistence;
866            @BeanReference(type = ResourceActionPersistence.class)
867            protected ResourceActionPersistence resourceActionPersistence;
868            @BeanReference(type = ResourceCodePersistence.class)
869            protected ResourceCodePersistence resourceCodePersistence;
870            @BeanReference(type = ResourcePermissionPersistence.class)
871            protected ResourcePermissionPersistence resourcePermissionPersistence;
872            @BeanReference(type = RolePersistence.class)
873            protected RolePersistence rolePersistence;
874            @BeanReference(type = ServiceComponentPersistence.class)
875            protected ServiceComponentPersistence serviceComponentPersistence;
876            @BeanReference(type = ShardPersistence.class)
877            protected ShardPersistence shardPersistence;
878            @BeanReference(type = SubscriptionPersistence.class)
879            protected SubscriptionPersistence subscriptionPersistence;
880            @BeanReference(type = TicketPersistence.class)
881            protected TicketPersistence ticketPersistence;
882            @BeanReference(type = TeamPersistence.class)
883            protected TeamPersistence teamPersistence;
884            @BeanReference(type = UserPersistence.class)
885            protected UserPersistence userPersistence;
886            @BeanReference(type = UserGroupPersistence.class)
887            protected UserGroupPersistence userGroupPersistence;
888            @BeanReference(type = UserGroupGroupRolePersistence.class)
889            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
890            @BeanReference(type = UserGroupRolePersistence.class)
891            protected UserGroupRolePersistence userGroupRolePersistence;
892            @BeanReference(type = UserIdMapperPersistence.class)
893            protected UserIdMapperPersistence userIdMapperPersistence;
894            @BeanReference(type = UserTrackerPersistence.class)
895            protected UserTrackerPersistence userTrackerPersistence;
896            @BeanReference(type = UserTrackerPathPersistence.class)
897            protected UserTrackerPathPersistence userTrackerPathPersistence;
898            @BeanReference(type = WebDAVPropsPersistence.class)
899            protected WebDAVPropsPersistence webDAVPropsPersistence;
900            @BeanReference(type = WebsitePersistence.class)
901            protected WebsitePersistence websitePersistence;
902            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
903            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
904            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
905            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
906            private static final String _SQL_SELECT_RELEASE = "SELECT release FROM Release release";
907            private static final String _SQL_SELECT_RELEASE_WHERE = "SELECT release FROM Release release WHERE ";
908            private static final String _SQL_COUNT_RELEASE = "SELECT COUNT(release) FROM Release release";
909            private static final String _SQL_COUNT_RELEASE_WHERE = "SELECT COUNT(release) FROM Release release WHERE ";
910            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_1 =
911                    "release.servletContextName IS NULL";
912            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_2 =
913                    "release.servletContextName = ?";
914            private static final String _FINDER_COLUMN_SERVLETCONTEXTNAME_SERVLETCONTEXTNAME_3 =
915                    "(release.servletContextName IS NULL OR release.servletContextName = ?)";
916            private static final String _ORDER_BY_ENTITY_ALIAS = "release.";
917            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Release exists with the primary key ";
918            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Release exists with the key {";
919            private static Log _log = LogFactoryUtil.getLog(ReleasePersistenceImpl.class);
920    }