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