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