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