001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchTicketException;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.Validator;
035    import com.liferay.portal.model.CacheModel;
036    import com.liferay.portal.model.MVCCModel;
037    import com.liferay.portal.model.Ticket;
038    import com.liferay.portal.model.impl.TicketImpl;
039    import com.liferay.portal.model.impl.TicketModelImpl;
040    import com.liferay.portal.service.persistence.TicketPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.Collections;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.Map;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the ticket service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see TicketPersistence
061     * @see com.liferay.portal.service.persistence.TicketUtil
062     * @generated
063     */
064    @ProviderType
065    public class TicketPersistenceImpl extends BasePersistenceImpl<Ticket>
066            implements TicketPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * 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.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = TicketImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
078                            TicketModelImpl.FINDER_CACHE_ENABLED, TicketImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
081                            TicketModelImpl.FINDER_CACHE_ENABLED, TicketImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
084                            TicketModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_FETCH_BY_KEY = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
087                            TicketModelImpl.FINDER_CACHE_ENABLED, TicketImpl.class,
088                            FINDER_CLASS_NAME_ENTITY, "fetchByKey",
089                            new String[] { String.class.getName() },
090                            TicketModelImpl.KEY_COLUMN_BITMASK);
091            public static final FinderPath FINDER_PATH_COUNT_BY_KEY = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
092                            TicketModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByKey",
094                            new String[] { String.class.getName() });
095    
096            /**
097             * Returns the ticket where key = &#63; or throws a {@link NoSuchTicketException} if it could not be found.
098             *
099             * @param key the key
100             * @return the matching ticket
101             * @throws NoSuchTicketException if a matching ticket could not be found
102             */
103            @Override
104            public Ticket findByKey(String key) throws NoSuchTicketException {
105                    Ticket ticket = fetchByKey(key);
106    
107                    if (ticket == null) {
108                            StringBundler msg = new StringBundler(4);
109    
110                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111    
112                            msg.append("key=");
113                            msg.append(key);
114    
115                            msg.append(StringPool.CLOSE_CURLY_BRACE);
116    
117                            if (_log.isWarnEnabled()) {
118                                    _log.warn(msg.toString());
119                            }
120    
121                            throw new NoSuchTicketException(msg.toString());
122                    }
123    
124                    return ticket;
125            }
126    
127            /**
128             * Returns the ticket where key = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
129             *
130             * @param key the key
131             * @return the matching ticket, or <code>null</code> if a matching ticket could not be found
132             */
133            @Override
134            public Ticket fetchByKey(String key) {
135                    return fetchByKey(key, true);
136            }
137    
138            /**
139             * Returns the ticket where key = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
140             *
141             * @param key the key
142             * @param retrieveFromCache whether to use the finder cache
143             * @return the matching ticket, or <code>null</code> if a matching ticket could not be found
144             */
145            @Override
146            public Ticket fetchByKey(String key, boolean retrieveFromCache) {
147                    Object[] finderArgs = new Object[] { key };
148    
149                    Object result = null;
150    
151                    if (retrieveFromCache) {
152                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_KEY,
153                                            finderArgs, this);
154                    }
155    
156                    if (result instanceof Ticket) {
157                            Ticket ticket = (Ticket)result;
158    
159                            if (!Validator.equals(key, ticket.getKey())) {
160                                    result = null;
161                            }
162                    }
163    
164                    if (result == null) {
165                            StringBundler query = new StringBundler(3);
166    
167                            query.append(_SQL_SELECT_TICKET_WHERE);
168    
169                            boolean bindKey = false;
170    
171                            if (key == null) {
172                                    query.append(_FINDER_COLUMN_KEY_KEY_1);
173                            }
174                            else if (key.equals(StringPool.BLANK)) {
175                                    query.append(_FINDER_COLUMN_KEY_KEY_3);
176                            }
177                            else {
178                                    bindKey = true;
179    
180                                    query.append(_FINDER_COLUMN_KEY_KEY_2);
181                            }
182    
183                            String sql = query.toString();
184    
185                            Session session = null;
186    
187                            try {
188                                    session = openSession();
189    
190                                    Query q = session.createQuery(sql);
191    
192                                    QueryPos qPos = QueryPos.getInstance(q);
193    
194                                    if (bindKey) {
195                                            qPos.add(key);
196                                    }
197    
198                                    List<Ticket> list = q.list();
199    
200                                    if (list.isEmpty()) {
201                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEY,
202                                                    finderArgs, list);
203                                    }
204                                    else {
205                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
206                                                    _log.warn(
207                                                            "TicketPersistenceImpl.fetchByKey(String, boolean) with parameters (" +
208                                                            StringUtil.merge(finderArgs) +
209                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
210                                            }
211    
212                                            Ticket ticket = list.get(0);
213    
214                                            result = ticket;
215    
216                                            cacheResult(ticket);
217    
218                                            if ((ticket.getKey() == null) ||
219                                                            !ticket.getKey().equals(key)) {
220                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEY,
221                                                            finderArgs, ticket);
222                                            }
223                                    }
224                            }
225                            catch (Exception e) {
226                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_KEY,
227                                            finderArgs);
228    
229                                    throw processException(e);
230                            }
231                            finally {
232                                    closeSession(session);
233                            }
234                    }
235    
236                    if (result instanceof List<?>) {
237                            return null;
238                    }
239                    else {
240                            return (Ticket)result;
241                    }
242            }
243    
244            /**
245             * Removes the ticket where key = &#63; from the database.
246             *
247             * @param key the key
248             * @return the ticket that was removed
249             */
250            @Override
251            public Ticket removeByKey(String key) throws NoSuchTicketException {
252                    Ticket ticket = findByKey(key);
253    
254                    return remove(ticket);
255            }
256    
257            /**
258             * Returns the number of tickets where key = &#63;.
259             *
260             * @param key the key
261             * @return the number of matching tickets
262             */
263            @Override
264            public int countByKey(String key) {
265                    FinderPath finderPath = FINDER_PATH_COUNT_BY_KEY;
266    
267                    Object[] finderArgs = new Object[] { key };
268    
269                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
270                                    this);
271    
272                    if (count == null) {
273                            StringBundler query = new StringBundler(2);
274    
275                            query.append(_SQL_COUNT_TICKET_WHERE);
276    
277                            boolean bindKey = false;
278    
279                            if (key == null) {
280                                    query.append(_FINDER_COLUMN_KEY_KEY_1);
281                            }
282                            else if (key.equals(StringPool.BLANK)) {
283                                    query.append(_FINDER_COLUMN_KEY_KEY_3);
284                            }
285                            else {
286                                    bindKey = true;
287    
288                                    query.append(_FINDER_COLUMN_KEY_KEY_2);
289                            }
290    
291                            String sql = query.toString();
292    
293                            Session session = null;
294    
295                            try {
296                                    session = openSession();
297    
298                                    Query q = session.createQuery(sql);
299    
300                                    QueryPos qPos = QueryPos.getInstance(q);
301    
302                                    if (bindKey) {
303                                            qPos.add(key);
304                                    }
305    
306                                    count = (Long)q.uniqueResult();
307    
308                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
309                            }
310                            catch (Exception e) {
311                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
312    
313                                    throw processException(e);
314                            }
315                            finally {
316                                    closeSession(session);
317                            }
318                    }
319    
320                    return count.intValue();
321            }
322    
323            private static final String _FINDER_COLUMN_KEY_KEY_1 = "ticket.key IS NULL";
324            private static final String _FINDER_COLUMN_KEY_KEY_2 = "ticket.key = ?";
325            private static final String _FINDER_COLUMN_KEY_KEY_3 = "(ticket.key IS NULL OR ticket.key = '')";
326            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
327                            TicketModelImpl.FINDER_CACHE_ENABLED, TicketImpl.class,
328                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_T",
329                            new String[] {
330                                    Long.class.getName(), Long.class.getName(),
331                                    Integer.class.getName(),
332                                    
333                            Integer.class.getName(), Integer.class.getName(),
334                                    OrderByComparator.class.getName()
335                            });
336            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
337                            TicketModelImpl.FINDER_CACHE_ENABLED, TicketImpl.class,
338                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_T",
339                            new String[] {
340                                    Long.class.getName(), Long.class.getName(),
341                                    Integer.class.getName()
342                            },
343                            TicketModelImpl.CLASSNAMEID_COLUMN_BITMASK |
344                            TicketModelImpl.CLASSPK_COLUMN_BITMASK |
345                            TicketModelImpl.TYPE_COLUMN_BITMASK);
346            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T = new FinderPath(TicketModelImpl.ENTITY_CACHE_ENABLED,
347                            TicketModelImpl.FINDER_CACHE_ENABLED, Long.class,
348                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T",
349                            new String[] {
350                                    Long.class.getName(), Long.class.getName(),
351                                    Integer.class.getName()
352                            });
353    
354            /**
355             * Returns all the tickets where classNameId = &#63; and classPK = &#63; and type = &#63;.
356             *
357             * @param classNameId the class name ID
358             * @param classPK the class p k
359             * @param type the type
360             * @return the matching tickets
361             */
362            @Override
363            public List<Ticket> findByC_C_T(long classNameId, long classPK, int type) {
364                    return findByC_C_T(classNameId, classPK, type, QueryUtil.ALL_POS,
365                            QueryUtil.ALL_POS, null);
366            }
367    
368            /**
369             * Returns a range of all the tickets where classNameId = &#63; and classPK = &#63; and type = &#63;.
370             *
371             * <p>
372             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TicketModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
373             * </p>
374             *
375             * @param classNameId the class name ID
376             * @param classPK the class p k
377             * @param type the type
378             * @param start the lower bound of the range of tickets
379             * @param end the upper bound of the range of tickets (not inclusive)
380             * @return the range of matching tickets
381             */
382            @Override
383            public List<Ticket> findByC_C_T(long classNameId, long classPK, int type,
384                    int start, int end) {
385                    return findByC_C_T(classNameId, classPK, type, start, end, null);
386            }
387    
388            /**
389             * Returns an ordered range of all the tickets where classNameId = &#63; and classPK = &#63; and type = &#63;.
390             *
391             * <p>
392             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TicketModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
393             * </p>
394             *
395             * @param classNameId the class name ID
396             * @param classPK the class p k
397             * @param type the type
398             * @param start the lower bound of the range of tickets
399             * @param end the upper bound of the range of tickets (not inclusive)
400             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
401             * @return the ordered range of matching tickets
402             */
403            @Override
404            public List<Ticket> findByC_C_T(long classNameId, long classPK, int type,
405                    int start, int end, OrderByComparator<Ticket> orderByComparator) {
406                    boolean pagination = true;
407                    FinderPath finderPath = null;
408                    Object[] finderArgs = null;
409    
410                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
411                                    (orderByComparator == null)) {
412                            pagination = false;
413                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T;
414                            finderArgs = new Object[] { classNameId, classPK, type };
415                    }
416                    else {
417                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T;
418                            finderArgs = new Object[] {
419                                            classNameId, classPK, type,
420                                            
421                                            start, end, orderByComparator
422                                    };
423                    }
424    
425                    List<Ticket> list = (List<Ticket>)FinderCacheUtil.getResult(finderPath,
426                                    finderArgs, this);
427    
428                    if ((list != null) && !list.isEmpty()) {
429                            for (Ticket ticket : list) {
430                                    if ((classNameId != ticket.getClassNameId()) ||
431                                                    (classPK != ticket.getClassPK()) ||
432                                                    (type != ticket.getType())) {
433                                            list = null;
434    
435                                            break;
436                                    }
437                            }
438                    }
439    
440                    if (list == null) {
441                            StringBundler query = null;
442    
443                            if (orderByComparator != null) {
444                                    query = new StringBundler(5 +
445                                                    (orderByComparator.getOrderByFields().length * 3));
446                            }
447                            else {
448                                    query = new StringBundler(5);
449                            }
450    
451                            query.append(_SQL_SELECT_TICKET_WHERE);
452    
453                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
454    
455                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
456    
457                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
458    
459                            if (orderByComparator != null) {
460                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
461                                            orderByComparator);
462                            }
463                            else
464                             if (pagination) {
465                                    query.append(TicketModelImpl.ORDER_BY_JPQL);
466                            }
467    
468                            String sql = query.toString();
469    
470                            Session session = null;
471    
472                            try {
473                                    session = openSession();
474    
475                                    Query q = session.createQuery(sql);
476    
477                                    QueryPos qPos = QueryPos.getInstance(q);
478    
479                                    qPos.add(classNameId);
480    
481                                    qPos.add(classPK);
482    
483                                    qPos.add(type);
484    
485                                    if (!pagination) {
486                                            list = (List<Ticket>)QueryUtil.list(q, getDialect(), start,
487                                                            end, false);
488    
489                                            Collections.sort(list);
490    
491                                            list = Collections.unmodifiableList(list);
492                                    }
493                                    else {
494                                            list = (List<Ticket>)QueryUtil.list(q, getDialect(), start,
495                                                            end);
496                                    }
497    
498                                    cacheResult(list);
499    
500                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
501                            }
502                            catch (Exception e) {
503                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
504    
505                                    throw processException(e);
506                            }
507                            finally {
508                                    closeSession(session);
509                            }
510                    }
511    
512                    return list;
513            }
514    
515            /**
516             * Returns the first ticket in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
517             *
518             * @param classNameId the class name ID
519             * @param classPK the class p k
520             * @param type the type
521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
522             * @return the first matching ticket
523             * @throws NoSuchTicketException if a matching ticket could not be found
524             */
525            @Override
526            public Ticket findByC_C_T_First(long classNameId, long classPK, int type,
527                    OrderByComparator<Ticket> orderByComparator)
528                    throws NoSuchTicketException {
529                    Ticket ticket = fetchByC_C_T_First(classNameId, classPK, type,
530                                    orderByComparator);
531    
532                    if (ticket != null) {
533                            return ticket;
534                    }
535    
536                    StringBundler msg = new StringBundler(8);
537    
538                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
539    
540                    msg.append("classNameId=");
541                    msg.append(classNameId);
542    
543                    msg.append(", classPK=");
544                    msg.append(classPK);
545    
546                    msg.append(", type=");
547                    msg.append(type);
548    
549                    msg.append(StringPool.CLOSE_CURLY_BRACE);
550    
551                    throw new NoSuchTicketException(msg.toString());
552            }
553    
554            /**
555             * Returns the first ticket in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
556             *
557             * @param classNameId the class name ID
558             * @param classPK the class p k
559             * @param type the type
560             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
561             * @return the first matching ticket, or <code>null</code> if a matching ticket could not be found
562             */
563            @Override
564            public Ticket fetchByC_C_T_First(long classNameId, long classPK, int type,
565                    OrderByComparator<Ticket> orderByComparator) {
566                    List<Ticket> list = findByC_C_T(classNameId, classPK, type, 0, 1,
567                                    orderByComparator);
568    
569                    if (!list.isEmpty()) {
570                            return list.get(0);
571                    }
572    
573                    return null;
574            }
575    
576            /**
577             * Returns the last ticket in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
578             *
579             * @param classNameId the class name ID
580             * @param classPK the class p k
581             * @param type the type
582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
583             * @return the last matching ticket
584             * @throws NoSuchTicketException if a matching ticket could not be found
585             */
586            @Override
587            public Ticket findByC_C_T_Last(long classNameId, long classPK, int type,
588                    OrderByComparator<Ticket> orderByComparator)
589                    throws NoSuchTicketException {
590                    Ticket ticket = fetchByC_C_T_Last(classNameId, classPK, type,
591                                    orderByComparator);
592    
593                    if (ticket != null) {
594                            return ticket;
595                    }
596    
597                    StringBundler msg = new StringBundler(8);
598    
599                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
600    
601                    msg.append("classNameId=");
602                    msg.append(classNameId);
603    
604                    msg.append(", classPK=");
605                    msg.append(classPK);
606    
607                    msg.append(", type=");
608                    msg.append(type);
609    
610                    msg.append(StringPool.CLOSE_CURLY_BRACE);
611    
612                    throw new NoSuchTicketException(msg.toString());
613            }
614    
615            /**
616             * Returns the last ticket in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
617             *
618             * @param classNameId the class name ID
619             * @param classPK the class p k
620             * @param type the type
621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
622             * @return the last matching ticket, or <code>null</code> if a matching ticket could not be found
623             */
624            @Override
625            public Ticket fetchByC_C_T_Last(long classNameId, long classPK, int type,
626                    OrderByComparator<Ticket> orderByComparator) {
627                    int count = countByC_C_T(classNameId, classPK, type);
628    
629                    if (count == 0) {
630                            return null;
631                    }
632    
633                    List<Ticket> list = findByC_C_T(classNameId, classPK, type, count - 1,
634                                    count, orderByComparator);
635    
636                    if (!list.isEmpty()) {
637                            return list.get(0);
638                    }
639    
640                    return null;
641            }
642    
643            /**
644             * Returns the tickets before and after the current ticket in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
645             *
646             * @param ticketId the primary key of the current ticket
647             * @param classNameId the class name ID
648             * @param classPK the class p k
649             * @param type the type
650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
651             * @return the previous, current, and next ticket
652             * @throws NoSuchTicketException if a ticket with the primary key could not be found
653             */
654            @Override
655            public Ticket[] findByC_C_T_PrevAndNext(long ticketId, long classNameId,
656                    long classPK, int type, OrderByComparator<Ticket> orderByComparator)
657                    throws NoSuchTicketException {
658                    Ticket ticket = findByPrimaryKey(ticketId);
659    
660                    Session session = null;
661    
662                    try {
663                            session = openSession();
664    
665                            Ticket[] array = new TicketImpl[3];
666    
667                            array[0] = getByC_C_T_PrevAndNext(session, ticket, classNameId,
668                                            classPK, type, orderByComparator, true);
669    
670                            array[1] = ticket;
671    
672                            array[2] = getByC_C_T_PrevAndNext(session, ticket, classNameId,
673                                            classPK, type, orderByComparator, false);
674    
675                            return array;
676                    }
677                    catch (Exception e) {
678                            throw processException(e);
679                    }
680                    finally {
681                            closeSession(session);
682                    }
683            }
684    
685            protected Ticket getByC_C_T_PrevAndNext(Session session, Ticket ticket,
686                    long classNameId, long classPK, int type,
687                    OrderByComparator<Ticket> orderByComparator, boolean previous) {
688                    StringBundler query = null;
689    
690                    if (orderByComparator != null) {
691                            query = new StringBundler(6 +
692                                            (orderByComparator.getOrderByFields().length * 6));
693                    }
694                    else {
695                            query = new StringBundler(3);
696                    }
697    
698                    query.append(_SQL_SELECT_TICKET_WHERE);
699    
700                    query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
701    
702                    query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
703    
704                    query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
705    
706                    if (orderByComparator != null) {
707                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
708    
709                            if (orderByConditionFields.length > 0) {
710                                    query.append(WHERE_AND);
711                            }
712    
713                            for (int i = 0; i < orderByConditionFields.length; i++) {
714                                    query.append(_ORDER_BY_ENTITY_ALIAS);
715                                    query.append(orderByConditionFields[i]);
716    
717                                    if ((i + 1) < orderByConditionFields.length) {
718                                            if (orderByComparator.isAscending() ^ previous) {
719                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
720                                            }
721                                            else {
722                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
723                                            }
724                                    }
725                                    else {
726                                            if (orderByComparator.isAscending() ^ previous) {
727                                                    query.append(WHERE_GREATER_THAN);
728                                            }
729                                            else {
730                                                    query.append(WHERE_LESSER_THAN);
731                                            }
732                                    }
733                            }
734    
735                            query.append(ORDER_BY_CLAUSE);
736    
737                            String[] orderByFields = orderByComparator.getOrderByFields();
738    
739                            for (int i = 0; i < orderByFields.length; i++) {
740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
741                                    query.append(orderByFields[i]);
742    
743                                    if ((i + 1) < orderByFields.length) {
744                                            if (orderByComparator.isAscending() ^ previous) {
745                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
746                                            }
747                                            else {
748                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
749                                            }
750                                    }
751                                    else {
752                                            if (orderByComparator.isAscending() ^ previous) {
753                                                    query.append(ORDER_BY_ASC);
754                                            }
755                                            else {
756                                                    query.append(ORDER_BY_DESC);
757                                            }
758                                    }
759                            }
760                    }
761                    else {
762                            query.append(TicketModelImpl.ORDER_BY_JPQL);
763                    }
764    
765                    String sql = query.toString();
766    
767                    Query q = session.createQuery(sql);
768    
769                    q.setFirstResult(0);
770                    q.setMaxResults(2);
771    
772                    QueryPos qPos = QueryPos.getInstance(q);
773    
774                    qPos.add(classNameId);
775    
776                    qPos.add(classPK);
777    
778                    qPos.add(type);
779    
780                    if (orderByComparator != null) {
781                            Object[] values = orderByComparator.getOrderByConditionValues(ticket);
782    
783                            for (Object value : values) {
784                                    qPos.add(value);
785                            }
786                    }
787    
788                    List<Ticket> list = q.list();
789    
790                    if (list.size() == 2) {
791                            return list.get(1);
792                    }
793                    else {
794                            return null;
795                    }
796            }
797    
798            /**
799             * Removes all the tickets where classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
800             *
801             * @param classNameId the class name ID
802             * @param classPK the class p k
803             * @param type the type
804             */
805            @Override
806            public void removeByC_C_T(long classNameId, long classPK, int type) {
807                    for (Ticket ticket : findByC_C_T(classNameId, classPK, type,
808                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
809                            remove(ticket);
810                    }
811            }
812    
813            /**
814             * Returns the number of tickets where classNameId = &#63; and classPK = &#63; and type = &#63;.
815             *
816             * @param classNameId the class name ID
817             * @param classPK the class p k
818             * @param type the type
819             * @return the number of matching tickets
820             */
821            @Override
822            public int countByC_C_T(long classNameId, long classPK, int type) {
823                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_T;
824    
825                    Object[] finderArgs = new Object[] { classNameId, classPK, type };
826    
827                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
828                                    this);
829    
830                    if (count == null) {
831                            StringBundler query = new StringBundler(4);
832    
833                            query.append(_SQL_COUNT_TICKET_WHERE);
834    
835                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
836    
837                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
838    
839                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
840    
841                            String sql = query.toString();
842    
843                            Session session = null;
844    
845                            try {
846                                    session = openSession();
847    
848                                    Query q = session.createQuery(sql);
849    
850                                    QueryPos qPos = QueryPos.getInstance(q);
851    
852                                    qPos.add(classNameId);
853    
854                                    qPos.add(classPK);
855    
856                                    qPos.add(type);
857    
858                                    count = (Long)q.uniqueResult();
859    
860                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
861                            }
862                            catch (Exception e) {
863                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
864    
865                                    throw processException(e);
866                            }
867                            finally {
868                                    closeSession(session);
869                            }
870                    }
871    
872                    return count.intValue();
873            }
874    
875            private static final String _FINDER_COLUMN_C_C_T_CLASSNAMEID_2 = "ticket.classNameId = ? AND ";
876            private static final String _FINDER_COLUMN_C_C_T_CLASSPK_2 = "ticket.classPK = ? AND ";
877            private static final String _FINDER_COLUMN_C_C_T_TYPE_2 = "ticket.type = ?";
878    
879            public TicketPersistenceImpl() {
880                    setModelClass(Ticket.class);
881            }
882    
883            /**
884             * Caches the ticket in the entity cache if it is enabled.
885             *
886             * @param ticket the ticket
887             */
888            @Override
889            public void cacheResult(Ticket ticket) {
890                    EntityCacheUtil.putResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
891                            TicketImpl.class, ticket.getPrimaryKey(), ticket);
892    
893                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEY,
894                            new Object[] { ticket.getKey() }, ticket);
895    
896                    ticket.resetOriginalValues();
897            }
898    
899            /**
900             * Caches the tickets in the entity cache if it is enabled.
901             *
902             * @param tickets the tickets
903             */
904            @Override
905            public void cacheResult(List<Ticket> tickets) {
906                    for (Ticket ticket : tickets) {
907                            if (EntityCacheUtil.getResult(
908                                                    TicketModelImpl.ENTITY_CACHE_ENABLED, TicketImpl.class,
909                                                    ticket.getPrimaryKey()) == null) {
910                                    cacheResult(ticket);
911                            }
912                            else {
913                                    ticket.resetOriginalValues();
914                            }
915                    }
916            }
917    
918            /**
919             * Clears the cache for all tickets.
920             *
921             * <p>
922             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
923             * </p>
924             */
925            @Override
926            public void clearCache() {
927                    EntityCacheUtil.clearCache(TicketImpl.class);
928    
929                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
930                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
931                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
932            }
933    
934            /**
935             * Clears the cache for the ticket.
936             *
937             * <p>
938             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
939             * </p>
940             */
941            @Override
942            public void clearCache(Ticket ticket) {
943                    EntityCacheUtil.removeResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
944                            TicketImpl.class, ticket.getPrimaryKey());
945    
946                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
947                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
948    
949                    clearUniqueFindersCache(ticket);
950            }
951    
952            @Override
953            public void clearCache(List<Ticket> tickets) {
954                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
955                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
956    
957                    for (Ticket ticket : tickets) {
958                            EntityCacheUtil.removeResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
959                                    TicketImpl.class, ticket.getPrimaryKey());
960    
961                            clearUniqueFindersCache(ticket);
962                    }
963            }
964    
965            protected void cacheUniqueFindersCache(Ticket ticket) {
966                    if (ticket.isNew()) {
967                            Object[] args = new Object[] { ticket.getKey() };
968    
969                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_KEY, args,
970                                    Long.valueOf(1));
971                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEY, args, ticket);
972                    }
973                    else {
974                            TicketModelImpl ticketModelImpl = (TicketModelImpl)ticket;
975    
976                            if ((ticketModelImpl.getColumnBitmask() &
977                                            FINDER_PATH_FETCH_BY_KEY.getColumnBitmask()) != 0) {
978                                    Object[] args = new Object[] { ticket.getKey() };
979    
980                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_KEY, args,
981                                            Long.valueOf(1));
982                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEY, args, ticket);
983                            }
984                    }
985            }
986    
987            protected void clearUniqueFindersCache(Ticket ticket) {
988                    TicketModelImpl ticketModelImpl = (TicketModelImpl)ticket;
989    
990                    Object[] args = new Object[] { ticket.getKey() };
991    
992                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_KEY, args);
993                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_KEY, args);
994    
995                    if ((ticketModelImpl.getColumnBitmask() &
996                                    FINDER_PATH_FETCH_BY_KEY.getColumnBitmask()) != 0) {
997                            args = new Object[] { ticketModelImpl.getOriginalKey() };
998    
999                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_KEY, args);
1000                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_KEY, args);
1001                    }
1002            }
1003    
1004            /**
1005             * Creates a new ticket with the primary key. Does not add the ticket to the database.
1006             *
1007             * @param ticketId the primary key for the new ticket
1008             * @return the new ticket
1009             */
1010            @Override
1011            public Ticket create(long ticketId) {
1012                    Ticket ticket = new TicketImpl();
1013    
1014                    ticket.setNew(true);
1015                    ticket.setPrimaryKey(ticketId);
1016    
1017                    return ticket;
1018            }
1019    
1020            /**
1021             * Removes the ticket with the primary key from the database. Also notifies the appropriate model listeners.
1022             *
1023             * @param ticketId the primary key of the ticket
1024             * @return the ticket that was removed
1025             * @throws NoSuchTicketException if a ticket with the primary key could not be found
1026             */
1027            @Override
1028            public Ticket remove(long ticketId) throws NoSuchTicketException {
1029                    return remove((Serializable)ticketId);
1030            }
1031    
1032            /**
1033             * Removes the ticket with the primary key from the database. Also notifies the appropriate model listeners.
1034             *
1035             * @param primaryKey the primary key of the ticket
1036             * @return the ticket that was removed
1037             * @throws NoSuchTicketException if a ticket with the primary key could not be found
1038             */
1039            @Override
1040            public Ticket remove(Serializable primaryKey) throws NoSuchTicketException {
1041                    Session session = null;
1042    
1043                    try {
1044                            session = openSession();
1045    
1046                            Ticket ticket = (Ticket)session.get(TicketImpl.class, primaryKey);
1047    
1048                            if (ticket == null) {
1049                                    if (_log.isWarnEnabled()) {
1050                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1051                                    }
1052    
1053                                    throw new NoSuchTicketException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1054                                            primaryKey);
1055                            }
1056    
1057                            return remove(ticket);
1058                    }
1059                    catch (NoSuchTicketException nsee) {
1060                            throw nsee;
1061                    }
1062                    catch (Exception e) {
1063                            throw processException(e);
1064                    }
1065                    finally {
1066                            closeSession(session);
1067                    }
1068            }
1069    
1070            @Override
1071            protected Ticket removeImpl(Ticket ticket) {
1072                    ticket = toUnwrappedModel(ticket);
1073    
1074                    Session session = null;
1075    
1076                    try {
1077                            session = openSession();
1078    
1079                            if (!session.contains(ticket)) {
1080                                    ticket = (Ticket)session.get(TicketImpl.class,
1081                                                    ticket.getPrimaryKeyObj());
1082                            }
1083    
1084                            if (ticket != null) {
1085                                    session.delete(ticket);
1086                            }
1087                    }
1088                    catch (Exception e) {
1089                            throw processException(e);
1090                    }
1091                    finally {
1092                            closeSession(session);
1093                    }
1094    
1095                    if (ticket != null) {
1096                            clearCache(ticket);
1097                    }
1098    
1099                    return ticket;
1100            }
1101    
1102            @Override
1103            public Ticket updateImpl(Ticket ticket) {
1104                    ticket = toUnwrappedModel(ticket);
1105    
1106                    boolean isNew = ticket.isNew();
1107    
1108                    TicketModelImpl ticketModelImpl = (TicketModelImpl)ticket;
1109    
1110                    Session session = null;
1111    
1112                    try {
1113                            session = openSession();
1114    
1115                            if (ticket.isNew()) {
1116                                    session.save(ticket);
1117    
1118                                    ticket.setNew(false);
1119                            }
1120                            else {
1121                                    session.merge(ticket);
1122                            }
1123                    }
1124                    catch (Exception e) {
1125                            throw processException(e);
1126                    }
1127                    finally {
1128                            closeSession(session);
1129                    }
1130    
1131                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1132    
1133                    if (isNew || !TicketModelImpl.COLUMN_BITMASK_ENABLED) {
1134                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1135                    }
1136    
1137                    else {
1138                            if ((ticketModelImpl.getColumnBitmask() &
1139                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T.getColumnBitmask()) != 0) {
1140                                    Object[] args = new Object[] {
1141                                                    ticketModelImpl.getOriginalClassNameId(),
1142                                                    ticketModelImpl.getOriginalClassPK(),
1143                                                    ticketModelImpl.getOriginalType()
1144                                            };
1145    
1146                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
1147                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
1148                                            args);
1149    
1150                                    args = new Object[] {
1151                                                    ticketModelImpl.getClassNameId(),
1152                                                    ticketModelImpl.getClassPK(), ticketModelImpl.getType()
1153                                            };
1154    
1155                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
1156                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
1157                                            args);
1158                            }
1159                    }
1160    
1161                    EntityCacheUtil.putResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
1162                            TicketImpl.class, ticket.getPrimaryKey(), ticket, false);
1163    
1164                    clearUniqueFindersCache(ticket);
1165                    cacheUniqueFindersCache(ticket);
1166    
1167                    ticket.resetOriginalValues();
1168    
1169                    return ticket;
1170            }
1171    
1172            protected Ticket toUnwrappedModel(Ticket ticket) {
1173                    if (ticket instanceof TicketImpl) {
1174                            return ticket;
1175                    }
1176    
1177                    TicketImpl ticketImpl = new TicketImpl();
1178    
1179                    ticketImpl.setNew(ticket.isNew());
1180                    ticketImpl.setPrimaryKey(ticket.getPrimaryKey());
1181    
1182                    ticketImpl.setMvccVersion(ticket.getMvccVersion());
1183                    ticketImpl.setTicketId(ticket.getTicketId());
1184                    ticketImpl.setCompanyId(ticket.getCompanyId());
1185                    ticketImpl.setCreateDate(ticket.getCreateDate());
1186                    ticketImpl.setClassNameId(ticket.getClassNameId());
1187                    ticketImpl.setClassPK(ticket.getClassPK());
1188                    ticketImpl.setKey(ticket.getKey());
1189                    ticketImpl.setType(ticket.getType());
1190                    ticketImpl.setExtraInfo(ticket.getExtraInfo());
1191                    ticketImpl.setExpirationDate(ticket.getExpirationDate());
1192    
1193                    return ticketImpl;
1194            }
1195    
1196            /**
1197             * Returns the ticket with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1198             *
1199             * @param primaryKey the primary key of the ticket
1200             * @return the ticket
1201             * @throws NoSuchTicketException if a ticket with the primary key could not be found
1202             */
1203            @Override
1204            public Ticket findByPrimaryKey(Serializable primaryKey)
1205                    throws NoSuchTicketException {
1206                    Ticket ticket = fetchByPrimaryKey(primaryKey);
1207    
1208                    if (ticket == null) {
1209                            if (_log.isWarnEnabled()) {
1210                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1211                            }
1212    
1213                            throw new NoSuchTicketException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1214                                    primaryKey);
1215                    }
1216    
1217                    return ticket;
1218            }
1219    
1220            /**
1221             * Returns the ticket with the primary key or throws a {@link NoSuchTicketException} if it could not be found.
1222             *
1223             * @param ticketId the primary key of the ticket
1224             * @return the ticket
1225             * @throws NoSuchTicketException if a ticket with the primary key could not be found
1226             */
1227            @Override
1228            public Ticket findByPrimaryKey(long ticketId) throws NoSuchTicketException {
1229                    return findByPrimaryKey((Serializable)ticketId);
1230            }
1231    
1232            /**
1233             * Returns the ticket with the primary key or returns <code>null</code> if it could not be found.
1234             *
1235             * @param primaryKey the primary key of the ticket
1236             * @return the ticket, or <code>null</code> if a ticket with the primary key could not be found
1237             */
1238            @Override
1239            public Ticket fetchByPrimaryKey(Serializable primaryKey) {
1240                    Ticket ticket = (Ticket)EntityCacheUtil.getResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
1241                                    TicketImpl.class, primaryKey);
1242    
1243                    if (ticket == _nullTicket) {
1244                            return null;
1245                    }
1246    
1247                    if (ticket == null) {
1248                            Session session = null;
1249    
1250                            try {
1251                                    session = openSession();
1252    
1253                                    ticket = (Ticket)session.get(TicketImpl.class, primaryKey);
1254    
1255                                    if (ticket != null) {
1256                                            cacheResult(ticket);
1257                                    }
1258                                    else {
1259                                            EntityCacheUtil.putResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
1260                                                    TicketImpl.class, primaryKey, _nullTicket);
1261                                    }
1262                            }
1263                            catch (Exception e) {
1264                                    EntityCacheUtil.removeResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
1265                                            TicketImpl.class, primaryKey);
1266    
1267                                    throw processException(e);
1268                            }
1269                            finally {
1270                                    closeSession(session);
1271                            }
1272                    }
1273    
1274                    return ticket;
1275            }
1276    
1277            /**
1278             * Returns the ticket with the primary key or returns <code>null</code> if it could not be found.
1279             *
1280             * @param ticketId the primary key of the ticket
1281             * @return the ticket, or <code>null</code> if a ticket with the primary key could not be found
1282             */
1283            @Override
1284            public Ticket fetchByPrimaryKey(long ticketId) {
1285                    return fetchByPrimaryKey((Serializable)ticketId);
1286            }
1287    
1288            @Override
1289            public Map<Serializable, Ticket> fetchByPrimaryKeys(
1290                    Set<Serializable> primaryKeys) {
1291                    if (primaryKeys.isEmpty()) {
1292                            return Collections.emptyMap();
1293                    }
1294    
1295                    Map<Serializable, Ticket> map = new HashMap<Serializable, Ticket>();
1296    
1297                    if (primaryKeys.size() == 1) {
1298                            Iterator<Serializable> iterator = primaryKeys.iterator();
1299    
1300                            Serializable primaryKey = iterator.next();
1301    
1302                            Ticket ticket = fetchByPrimaryKey(primaryKey);
1303    
1304                            if (ticket != null) {
1305                                    map.put(primaryKey, ticket);
1306                            }
1307    
1308                            return map;
1309                    }
1310    
1311                    Set<Serializable> uncachedPrimaryKeys = null;
1312    
1313                    for (Serializable primaryKey : primaryKeys) {
1314                            Ticket ticket = (Ticket)EntityCacheUtil.getResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
1315                                            TicketImpl.class, primaryKey);
1316    
1317                            if (ticket == null) {
1318                                    if (uncachedPrimaryKeys == null) {
1319                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1320                                    }
1321    
1322                                    uncachedPrimaryKeys.add(primaryKey);
1323                            }
1324                            else {
1325                                    map.put(primaryKey, ticket);
1326                            }
1327                    }
1328    
1329                    if (uncachedPrimaryKeys == null) {
1330                            return map;
1331                    }
1332    
1333                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1334                                    1);
1335    
1336                    query.append(_SQL_SELECT_TICKET_WHERE_PKS_IN);
1337    
1338                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1339                            query.append(String.valueOf(primaryKey));
1340    
1341                            query.append(StringPool.COMMA);
1342                    }
1343    
1344                    query.setIndex(query.index() - 1);
1345    
1346                    query.append(StringPool.CLOSE_PARENTHESIS);
1347    
1348                    String sql = query.toString();
1349    
1350                    Session session = null;
1351    
1352                    try {
1353                            session = openSession();
1354    
1355                            Query q = session.createQuery(sql);
1356    
1357                            for (Ticket ticket : (List<Ticket>)q.list()) {
1358                                    map.put(ticket.getPrimaryKeyObj(), ticket);
1359    
1360                                    cacheResult(ticket);
1361    
1362                                    uncachedPrimaryKeys.remove(ticket.getPrimaryKeyObj());
1363                            }
1364    
1365                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1366                                    EntityCacheUtil.putResult(TicketModelImpl.ENTITY_CACHE_ENABLED,
1367                                            TicketImpl.class, primaryKey, _nullTicket);
1368                            }
1369                    }
1370                    catch (Exception e) {
1371                            throw processException(e);
1372                    }
1373                    finally {
1374                            closeSession(session);
1375                    }
1376    
1377                    return map;
1378            }
1379    
1380            /**
1381             * Returns all the tickets.
1382             *
1383             * @return the tickets
1384             */
1385            @Override
1386            public List<Ticket> findAll() {
1387                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1388            }
1389    
1390            /**
1391             * Returns a range of all the tickets.
1392             *
1393             * <p>
1394             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TicketModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1395             * </p>
1396             *
1397             * @param start the lower bound of the range of tickets
1398             * @param end the upper bound of the range of tickets (not inclusive)
1399             * @return the range of tickets
1400             */
1401            @Override
1402            public List<Ticket> findAll(int start, int end) {
1403                    return findAll(start, end, null);
1404            }
1405    
1406            /**
1407             * Returns an ordered range of all the tickets.
1408             *
1409             * <p>
1410             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TicketModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1411             * </p>
1412             *
1413             * @param start the lower bound of the range of tickets
1414             * @param end the upper bound of the range of tickets (not inclusive)
1415             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1416             * @return the ordered range of tickets
1417             */
1418            @Override
1419            public List<Ticket> findAll(int start, int end,
1420                    OrderByComparator<Ticket> orderByComparator) {
1421                    boolean pagination = true;
1422                    FinderPath finderPath = null;
1423                    Object[] finderArgs = null;
1424    
1425                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1426                                    (orderByComparator == null)) {
1427                            pagination = false;
1428                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1429                            finderArgs = FINDER_ARGS_EMPTY;
1430                    }
1431                    else {
1432                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1433                            finderArgs = new Object[] { start, end, orderByComparator };
1434                    }
1435    
1436                    List<Ticket> list = (List<Ticket>)FinderCacheUtil.getResult(finderPath,
1437                                    finderArgs, this);
1438    
1439                    if (list == null) {
1440                            StringBundler query = null;
1441                            String sql = null;
1442    
1443                            if (orderByComparator != null) {
1444                                    query = new StringBundler(2 +
1445                                                    (orderByComparator.getOrderByFields().length * 3));
1446    
1447                                    query.append(_SQL_SELECT_TICKET);
1448    
1449                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1450                                            orderByComparator);
1451    
1452                                    sql = query.toString();
1453                            }
1454                            else {
1455                                    sql = _SQL_SELECT_TICKET;
1456    
1457                                    if (pagination) {
1458                                            sql = sql.concat(TicketModelImpl.ORDER_BY_JPQL);
1459                                    }
1460                            }
1461    
1462                            Session session = null;
1463    
1464                            try {
1465                                    session = openSession();
1466    
1467                                    Query q = session.createQuery(sql);
1468    
1469                                    if (!pagination) {
1470                                            list = (List<Ticket>)QueryUtil.list(q, getDialect(), start,
1471                                                            end, false);
1472    
1473                                            Collections.sort(list);
1474    
1475                                            list = Collections.unmodifiableList(list);
1476                                    }
1477                                    else {
1478                                            list = (List<Ticket>)QueryUtil.list(q, getDialect(), start,
1479                                                            end);
1480                                    }
1481    
1482                                    cacheResult(list);
1483    
1484                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1485                            }
1486                            catch (Exception e) {
1487                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1488    
1489                                    throw processException(e);
1490                            }
1491                            finally {
1492                                    closeSession(session);
1493                            }
1494                    }
1495    
1496                    return list;
1497            }
1498    
1499            /**
1500             * Removes all the tickets from the database.
1501             *
1502             */
1503            @Override
1504            public void removeAll() {
1505                    for (Ticket ticket : findAll()) {
1506                            remove(ticket);
1507                    }
1508            }
1509    
1510            /**
1511             * Returns the number of tickets.
1512             *
1513             * @return the number of tickets
1514             */
1515            @Override
1516            public int countAll() {
1517                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1518                                    FINDER_ARGS_EMPTY, this);
1519    
1520                    if (count == null) {
1521                            Session session = null;
1522    
1523                            try {
1524                                    session = openSession();
1525    
1526                                    Query q = session.createQuery(_SQL_COUNT_TICKET);
1527    
1528                                    count = (Long)q.uniqueResult();
1529    
1530                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1531                                            FINDER_ARGS_EMPTY, count);
1532                            }
1533                            catch (Exception e) {
1534                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1535                                            FINDER_ARGS_EMPTY);
1536    
1537                                    throw processException(e);
1538                            }
1539                            finally {
1540                                    closeSession(session);
1541                            }
1542                    }
1543    
1544                    return count.intValue();
1545            }
1546    
1547            @Override
1548            protected Set<String> getBadColumnNames() {
1549                    return _badColumnNames;
1550            }
1551    
1552            /**
1553             * Initializes the ticket persistence.
1554             */
1555            public void afterPropertiesSet() {
1556            }
1557    
1558            public void destroy() {
1559                    EntityCacheUtil.removeCache(TicketImpl.class.getName());
1560                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1561                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1562                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1563            }
1564    
1565            private static final String _SQL_SELECT_TICKET = "SELECT ticket FROM Ticket ticket";
1566            private static final String _SQL_SELECT_TICKET_WHERE_PKS_IN = "SELECT ticket FROM Ticket ticket WHERE ticketId IN (";
1567            private static final String _SQL_SELECT_TICKET_WHERE = "SELECT ticket FROM Ticket ticket WHERE ";
1568            private static final String _SQL_COUNT_TICKET = "SELECT COUNT(ticket) FROM Ticket ticket";
1569            private static final String _SQL_COUNT_TICKET_WHERE = "SELECT COUNT(ticket) FROM Ticket ticket WHERE ";
1570            private static final String _ORDER_BY_ENTITY_ALIAS = "ticket.";
1571            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Ticket exists with the primary key ";
1572            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Ticket exists with the key {";
1573            private static final Log _log = LogFactoryUtil.getLog(TicketPersistenceImpl.class);
1574            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1575                                    "key", "type"
1576                            });
1577            private static final Ticket _nullTicket = new TicketImpl() {
1578                            @Override
1579                            public Object clone() {
1580                                    return this;
1581                            }
1582    
1583                            @Override
1584                            public CacheModel<Ticket> toCacheModel() {
1585                                    return _nullTicketCacheModel;
1586                            }
1587                    };
1588    
1589            private static final CacheModel<Ticket> _nullTicketCacheModel = new NullCacheModel();
1590    
1591            private static class NullCacheModel implements CacheModel<Ticket>,
1592                    MVCCModel {
1593                    @Override
1594                    public long getMvccVersion() {
1595                            return -1;
1596                    }
1597    
1598                    @Override
1599                    public void setMvccVersion(long mvccVersion) {
1600                    }
1601    
1602                    @Override
1603                    public Ticket toEntityModel() {
1604                            return _nullTicket;
1605                    }
1606            }
1607    }