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