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