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