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