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