001    /**
002     * Copyright (c) 2000-2013 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.NoSuchSystemEventException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
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.UnmodifiableList;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.SystemEvent;
040    import com.liferay.portal.model.impl.SystemEventImpl;
041    import com.liferay.portal.model.impl.SystemEventModelImpl;
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    import java.util.Set;
050    
051    /**
052     * The persistence implementation for the system event service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see SystemEventPersistence
060     * @see SystemEventUtil
061     * @generated
062     */
063    public class SystemEventPersistenceImpl extends BasePersistenceImpl<SystemEvent>
064            implements SystemEventPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link SystemEventUtil} to access the system event persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = SystemEventImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
076                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
079                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
082                            SystemEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
085                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
087                            new String[] {
088                                    Long.class.getName(),
089                                    
090                            Integer.class.getName(), Integer.class.getName(),
091                                    OrderByComparator.class.getName()
092                            });
093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
094                    new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
095                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
097                            new String[] { Long.class.getName() },
098                            SystemEventModelImpl.GROUPID_COLUMN_BITMASK |
099                            SystemEventModelImpl.CREATEDATE_COLUMN_BITMASK);
100            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
101                            SystemEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
103                            new String[] { Long.class.getName() });
104    
105            /**
106             * Returns all the system events where groupId = &#63;.
107             *
108             * @param groupId the group ID
109             * @return the matching system events
110             * @throws SystemException if a system exception occurred
111             */
112            @Override
113            public List<SystemEvent> findByGroupId(long groupId)
114                    throws SystemException {
115                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the system events where groupId = &#63;.
120             *
121             * <p>
122             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
123             * </p>
124             *
125             * @param groupId the group ID
126             * @param start the lower bound of the range of system events
127             * @param end the upper bound of the range of system events (not inclusive)
128             * @return the range of matching system events
129             * @throws SystemException if a system exception occurred
130             */
131            @Override
132            public List<SystemEvent> findByGroupId(long groupId, int start, int end)
133                    throws SystemException {
134                    return findByGroupId(groupId, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the system events where groupId = &#63;.
139             *
140             * <p>
141             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
142             * </p>
143             *
144             * @param groupId the group ID
145             * @param start the lower bound of the range of system events
146             * @param end the upper bound of the range of system events (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching system events
149             * @throws SystemException if a system exception occurred
150             */
151            @Override
152            public List<SystemEvent> findByGroupId(long groupId, int start, int end,
153                    OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
162                            finderArgs = new Object[] { groupId };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
166                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
167                    }
168    
169                    List<SystemEvent> list = (List<SystemEvent>)FinderCacheUtil.getResult(finderPath,
170                                    finderArgs, this);
171    
172                    if ((list != null) && !list.isEmpty()) {
173                            for (SystemEvent systemEvent : list) {
174                                    if ((groupId != systemEvent.getGroupId())) {
175                                            list = null;
176    
177                                            break;
178                                    }
179                            }
180                    }
181    
182                    if (list == null) {
183                            StringBundler query = null;
184    
185                            if (orderByComparator != null) {
186                                    query = new StringBundler(3 +
187                                                    (orderByComparator.getOrderByFields().length * 3));
188                            }
189                            else {
190                                    query = new StringBundler(3);
191                            }
192    
193                            query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
194    
195                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
196    
197                            if (orderByComparator != null) {
198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
199                                            orderByComparator);
200                            }
201                            else
202                             if (pagination) {
203                                    query.append(SystemEventModelImpl.ORDER_BY_JPQL);
204                            }
205    
206                            String sql = query.toString();
207    
208                            Session session = null;
209    
210                            try {
211                                    session = openSession();
212    
213                                    Query q = session.createQuery(sql);
214    
215                                    QueryPos qPos = QueryPos.getInstance(q);
216    
217                                    qPos.add(groupId);
218    
219                                    if (!pagination) {
220                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
221                                                            start, end, false);
222    
223                                            Collections.sort(list);
224    
225                                            list = new UnmodifiableList<SystemEvent>(list);
226                                    }
227                                    else {
228                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
229                                                            start, end);
230                                    }
231    
232                                    cacheResult(list);
233    
234                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
235                            }
236                            catch (Exception e) {
237                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
238    
239                                    throw processException(e);
240                            }
241                            finally {
242                                    closeSession(session);
243                            }
244                    }
245    
246                    return list;
247            }
248    
249            /**
250             * Returns the first system event in the ordered set where groupId = &#63;.
251             *
252             * @param groupId the group ID
253             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
254             * @return the first matching system event
255             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
256             * @throws SystemException if a system exception occurred
257             */
258            @Override
259            public SystemEvent findByGroupId_First(long groupId,
260                    OrderByComparator orderByComparator)
261                    throws NoSuchSystemEventException, SystemException {
262                    SystemEvent systemEvent = fetchByGroupId_First(groupId,
263                                    orderByComparator);
264    
265                    if (systemEvent != null) {
266                            return systemEvent;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("groupId=");
274                    msg.append(groupId);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchSystemEventException(msg.toString());
279            }
280    
281            /**
282             * Returns the first system event in the ordered set where groupId = &#63;.
283             *
284             * @param groupId the group ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching system event, or <code>null</code> if a matching system event could not be found
287             * @throws SystemException if a system exception occurred
288             */
289            @Override
290            public SystemEvent fetchByGroupId_First(long groupId,
291                    OrderByComparator orderByComparator) throws SystemException {
292                    List<SystemEvent> list = findByGroupId(groupId, 0, 1, orderByComparator);
293    
294                    if (!list.isEmpty()) {
295                            return list.get(0);
296                    }
297    
298                    return null;
299            }
300    
301            /**
302             * Returns the last system event in the ordered set where groupId = &#63;.
303             *
304             * @param groupId the group ID
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the last matching system event
307             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            @Override
311            public SystemEvent findByGroupId_Last(long groupId,
312                    OrderByComparator orderByComparator)
313                    throws NoSuchSystemEventException, SystemException {
314                    SystemEvent systemEvent = fetchByGroupId_Last(groupId, orderByComparator);
315    
316                    if (systemEvent != null) {
317                            return systemEvent;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("groupId=");
325                    msg.append(groupId);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchSystemEventException(msg.toString());
330            }
331    
332            /**
333             * Returns the last system event in the ordered set where groupId = &#63;.
334             *
335             * @param groupId the group ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching system event, or <code>null</code> if a matching system event could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            @Override
341            public SystemEvent fetchByGroupId_Last(long groupId,
342                    OrderByComparator orderByComparator) throws SystemException {
343                    int count = countByGroupId(groupId);
344    
345                    if (count == 0) {
346                            return null;
347                    }
348    
349                    List<SystemEvent> list = findByGroupId(groupId, count - 1, count,
350                                    orderByComparator);
351    
352                    if (!list.isEmpty()) {
353                            return list.get(0);
354                    }
355    
356                    return null;
357            }
358    
359            /**
360             * Returns the system events before and after the current system event in the ordered set where groupId = &#63;.
361             *
362             * @param systemEventId the primary key of the current system event
363             * @param groupId the group ID
364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
365             * @return the previous, current, and next system event
366             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
367             * @throws SystemException if a system exception occurred
368             */
369            @Override
370            public SystemEvent[] findByGroupId_PrevAndNext(long systemEventId,
371                    long groupId, OrderByComparator orderByComparator)
372                    throws NoSuchSystemEventException, SystemException {
373                    SystemEvent systemEvent = findByPrimaryKey(systemEventId);
374    
375                    Session session = null;
376    
377                    try {
378                            session = openSession();
379    
380                            SystemEvent[] array = new SystemEventImpl[3];
381    
382                            array[0] = getByGroupId_PrevAndNext(session, systemEvent, groupId,
383                                            orderByComparator, true);
384    
385                            array[1] = systemEvent;
386    
387                            array[2] = getByGroupId_PrevAndNext(session, systemEvent, groupId,
388                                            orderByComparator, false);
389    
390                            return array;
391                    }
392                    catch (Exception e) {
393                            throw processException(e);
394                    }
395                    finally {
396                            closeSession(session);
397                    }
398            }
399    
400            protected SystemEvent getByGroupId_PrevAndNext(Session session,
401                    SystemEvent systemEvent, long groupId,
402                    OrderByComparator orderByComparator, boolean previous) {
403                    StringBundler query = null;
404    
405                    if (orderByComparator != null) {
406                            query = new StringBundler(6 +
407                                            (orderByComparator.getOrderByFields().length * 6));
408                    }
409                    else {
410                            query = new StringBundler(3);
411                    }
412    
413                    query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
414    
415                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
416    
417                    if (orderByComparator != null) {
418                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
419    
420                            if (orderByConditionFields.length > 0) {
421                                    query.append(WHERE_AND);
422                            }
423    
424                            for (int i = 0; i < orderByConditionFields.length; i++) {
425                                    query.append(_ORDER_BY_ENTITY_ALIAS);
426                                    query.append(orderByConditionFields[i]);
427    
428                                    if ((i + 1) < orderByConditionFields.length) {
429                                            if (orderByComparator.isAscending() ^ previous) {
430                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
431                                            }
432                                            else {
433                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
434                                            }
435                                    }
436                                    else {
437                                            if (orderByComparator.isAscending() ^ previous) {
438                                                    query.append(WHERE_GREATER_THAN);
439                                            }
440                                            else {
441                                                    query.append(WHERE_LESSER_THAN);
442                                            }
443                                    }
444                            }
445    
446                            query.append(ORDER_BY_CLAUSE);
447    
448                            String[] orderByFields = orderByComparator.getOrderByFields();
449    
450                            for (int i = 0; i < orderByFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByFields[i]);
453    
454                                    if ((i + 1) < orderByFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(ORDER_BY_ASC);
465                                            }
466                                            else {
467                                                    query.append(ORDER_BY_DESC);
468                                            }
469                                    }
470                            }
471                    }
472                    else {
473                            query.append(SystemEventModelImpl.ORDER_BY_JPQL);
474                    }
475    
476                    String sql = query.toString();
477    
478                    Query q = session.createQuery(sql);
479    
480                    q.setFirstResult(0);
481                    q.setMaxResults(2);
482    
483                    QueryPos qPos = QueryPos.getInstance(q);
484    
485                    qPos.add(groupId);
486    
487                    if (orderByComparator != null) {
488                            Object[] values = orderByComparator.getOrderByConditionValues(systemEvent);
489    
490                            for (Object value : values) {
491                                    qPos.add(value);
492                            }
493                    }
494    
495                    List<SystemEvent> list = q.list();
496    
497                    if (list.size() == 2) {
498                            return list.get(1);
499                    }
500                    else {
501                            return null;
502                    }
503            }
504    
505            /**
506             * Removes all the system events where groupId = &#63; from the database.
507             *
508             * @param groupId the group ID
509             * @throws SystemException if a system exception occurred
510             */
511            @Override
512            public void removeByGroupId(long groupId) throws SystemException {
513                    for (SystemEvent systemEvent : findByGroupId(groupId,
514                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
515                            remove(systemEvent);
516                    }
517            }
518    
519            /**
520             * Returns the number of system events where groupId = &#63;.
521             *
522             * @param groupId the group ID
523             * @return the number of matching system events
524             * @throws SystemException if a system exception occurred
525             */
526            @Override
527            public int countByGroupId(long groupId) throws SystemException {
528                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
529    
530                    Object[] finderArgs = new Object[] { groupId };
531    
532                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
533                                    this);
534    
535                    if (count == null) {
536                            StringBundler query = new StringBundler(2);
537    
538                            query.append(_SQL_COUNT_SYSTEMEVENT_WHERE);
539    
540                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
541    
542                            String sql = query.toString();
543    
544                            Session session = null;
545    
546                            try {
547                                    session = openSession();
548    
549                                    Query q = session.createQuery(sql);
550    
551                                    QueryPos qPos = QueryPos.getInstance(q);
552    
553                                    qPos.add(groupId);
554    
555                                    count = (Long)q.uniqueResult();
556    
557                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
558                            }
559                            catch (Exception e) {
560                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
561    
562                                    throw processException(e);
563                            }
564                            finally {
565                                    closeSession(session);
566                            }
567                    }
568    
569                    return count.intValue();
570            }
571    
572            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "systemEvent.groupId = ?";
573            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
574                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
575                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
576                            new String[] {
577                                    Long.class.getName(), Long.class.getName(),
578                                    
579                            Integer.class.getName(), Integer.class.getName(),
580                                    OrderByComparator.class.getName()
581                            });
582            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
583                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
584                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
585                            new String[] { Long.class.getName(), Long.class.getName() },
586                            SystemEventModelImpl.GROUPID_COLUMN_BITMASK |
587                            SystemEventModelImpl.SYSTEMEVENTSETKEY_COLUMN_BITMASK |
588                            SystemEventModelImpl.CREATEDATE_COLUMN_BITMASK);
589            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
590                            SystemEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
591                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
592                            new String[] { Long.class.getName(), Long.class.getName() });
593    
594            /**
595             * Returns all the system events where groupId = &#63; and systemEventSetKey = &#63;.
596             *
597             * @param groupId the group ID
598             * @param systemEventSetKey the system event set key
599             * @return the matching system events
600             * @throws SystemException if a system exception occurred
601             */
602            @Override
603            public List<SystemEvent> findByG_S(long groupId, long systemEventSetKey)
604                    throws SystemException {
605                    return findByG_S(groupId, systemEventSetKey, QueryUtil.ALL_POS,
606                            QueryUtil.ALL_POS, null);
607            }
608    
609            /**
610             * Returns a range of all the system events where groupId = &#63; and systemEventSetKey = &#63;.
611             *
612             * <p>
613             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
614             * </p>
615             *
616             * @param groupId the group ID
617             * @param systemEventSetKey the system event set key
618             * @param start the lower bound of the range of system events
619             * @param end the upper bound of the range of system events (not inclusive)
620             * @return the range of matching system events
621             * @throws SystemException if a system exception occurred
622             */
623            @Override
624            public List<SystemEvent> findByG_S(long groupId, long systemEventSetKey,
625                    int start, int end) throws SystemException {
626                    return findByG_S(groupId, systemEventSetKey, start, end, null);
627            }
628    
629            /**
630             * Returns an ordered range of all the system events where groupId = &#63; and systemEventSetKey = &#63;.
631             *
632             * <p>
633             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
634             * </p>
635             *
636             * @param groupId the group ID
637             * @param systemEventSetKey the system event set key
638             * @param start the lower bound of the range of system events
639             * @param end the upper bound of the range of system events (not inclusive)
640             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
641             * @return the ordered range of matching system events
642             * @throws SystemException if a system exception occurred
643             */
644            @Override
645            public List<SystemEvent> findByG_S(long groupId, long systemEventSetKey,
646                    int start, int end, OrderByComparator orderByComparator)
647                    throws SystemException {
648                    boolean pagination = true;
649                    FinderPath finderPath = null;
650                    Object[] finderArgs = null;
651    
652                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
653                                    (orderByComparator == null)) {
654                            pagination = false;
655                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
656                            finderArgs = new Object[] { groupId, systemEventSetKey };
657                    }
658                    else {
659                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
660                            finderArgs = new Object[] {
661                                            groupId, systemEventSetKey,
662                                            
663                                            start, end, orderByComparator
664                                    };
665                    }
666    
667                    List<SystemEvent> list = (List<SystemEvent>)FinderCacheUtil.getResult(finderPath,
668                                    finderArgs, this);
669    
670                    if ((list != null) && !list.isEmpty()) {
671                            for (SystemEvent systemEvent : list) {
672                                    if ((groupId != systemEvent.getGroupId()) ||
673                                                    (systemEventSetKey != systemEvent.getSystemEventSetKey())) {
674                                            list = null;
675    
676                                            break;
677                                    }
678                            }
679                    }
680    
681                    if (list == null) {
682                            StringBundler query = null;
683    
684                            if (orderByComparator != null) {
685                                    query = new StringBundler(4 +
686                                                    (orderByComparator.getOrderByFields().length * 3));
687                            }
688                            else {
689                                    query = new StringBundler(4);
690                            }
691    
692                            query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
693    
694                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
695    
696                            query.append(_FINDER_COLUMN_G_S_SYSTEMEVENTSETKEY_2);
697    
698                            if (orderByComparator != null) {
699                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
700                                            orderByComparator);
701                            }
702                            else
703                             if (pagination) {
704                                    query.append(SystemEventModelImpl.ORDER_BY_JPQL);
705                            }
706    
707                            String sql = query.toString();
708    
709                            Session session = null;
710    
711                            try {
712                                    session = openSession();
713    
714                                    Query q = session.createQuery(sql);
715    
716                                    QueryPos qPos = QueryPos.getInstance(q);
717    
718                                    qPos.add(groupId);
719    
720                                    qPos.add(systemEventSetKey);
721    
722                                    if (!pagination) {
723                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
724                                                            start, end, false);
725    
726                                            Collections.sort(list);
727    
728                                            list = new UnmodifiableList<SystemEvent>(list);
729                                    }
730                                    else {
731                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
732                                                            start, end);
733                                    }
734    
735                                    cacheResult(list);
736    
737                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
738                            }
739                            catch (Exception e) {
740                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
741    
742                                    throw processException(e);
743                            }
744                            finally {
745                                    closeSession(session);
746                            }
747                    }
748    
749                    return list;
750            }
751    
752            /**
753             * Returns the first system event in the ordered set where groupId = &#63; and systemEventSetKey = &#63;.
754             *
755             * @param groupId the group ID
756             * @param systemEventSetKey the system event set key
757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
758             * @return the first matching system event
759             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
760             * @throws SystemException if a system exception occurred
761             */
762            @Override
763            public SystemEvent findByG_S_First(long groupId, long systemEventSetKey,
764                    OrderByComparator orderByComparator)
765                    throws NoSuchSystemEventException, SystemException {
766                    SystemEvent systemEvent = fetchByG_S_First(groupId, systemEventSetKey,
767                                    orderByComparator);
768    
769                    if (systemEvent != null) {
770                            return systemEvent;
771                    }
772    
773                    StringBundler msg = new StringBundler(6);
774    
775                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
776    
777                    msg.append("groupId=");
778                    msg.append(groupId);
779    
780                    msg.append(", systemEventSetKey=");
781                    msg.append(systemEventSetKey);
782    
783                    msg.append(StringPool.CLOSE_CURLY_BRACE);
784    
785                    throw new NoSuchSystemEventException(msg.toString());
786            }
787    
788            /**
789             * Returns the first system event in the ordered set where groupId = &#63; and systemEventSetKey = &#63;.
790             *
791             * @param groupId the group ID
792             * @param systemEventSetKey the system event set key
793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
794             * @return the first matching system event, or <code>null</code> if a matching system event could not be found
795             * @throws SystemException if a system exception occurred
796             */
797            @Override
798            public SystemEvent fetchByG_S_First(long groupId, long systemEventSetKey,
799                    OrderByComparator orderByComparator) throws SystemException {
800                    List<SystemEvent> list = findByG_S(groupId, systemEventSetKey, 0, 1,
801                                    orderByComparator);
802    
803                    if (!list.isEmpty()) {
804                            return list.get(0);
805                    }
806    
807                    return null;
808            }
809    
810            /**
811             * Returns the last system event in the ordered set where groupId = &#63; and systemEventSetKey = &#63;.
812             *
813             * @param groupId the group ID
814             * @param systemEventSetKey the system event set key
815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
816             * @return the last matching system event
817             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
818             * @throws SystemException if a system exception occurred
819             */
820            @Override
821            public SystemEvent findByG_S_Last(long groupId, long systemEventSetKey,
822                    OrderByComparator orderByComparator)
823                    throws NoSuchSystemEventException, SystemException {
824                    SystemEvent systemEvent = fetchByG_S_Last(groupId, systemEventSetKey,
825                                    orderByComparator);
826    
827                    if (systemEvent != null) {
828                            return systemEvent;
829                    }
830    
831                    StringBundler msg = new StringBundler(6);
832    
833                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
834    
835                    msg.append("groupId=");
836                    msg.append(groupId);
837    
838                    msg.append(", systemEventSetKey=");
839                    msg.append(systemEventSetKey);
840    
841                    msg.append(StringPool.CLOSE_CURLY_BRACE);
842    
843                    throw new NoSuchSystemEventException(msg.toString());
844            }
845    
846            /**
847             * Returns the last system event in the ordered set where groupId = &#63; and systemEventSetKey = &#63;.
848             *
849             * @param groupId the group ID
850             * @param systemEventSetKey the system event set key
851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
852             * @return the last matching system event, or <code>null</code> if a matching system event could not be found
853             * @throws SystemException if a system exception occurred
854             */
855            @Override
856            public SystemEvent fetchByG_S_Last(long groupId, long systemEventSetKey,
857                    OrderByComparator orderByComparator) throws SystemException {
858                    int count = countByG_S(groupId, systemEventSetKey);
859    
860                    if (count == 0) {
861                            return null;
862                    }
863    
864                    List<SystemEvent> list = findByG_S(groupId, systemEventSetKey,
865                                    count - 1, count, orderByComparator);
866    
867                    if (!list.isEmpty()) {
868                            return list.get(0);
869                    }
870    
871                    return null;
872            }
873    
874            /**
875             * Returns the system events before and after the current system event in the ordered set where groupId = &#63; and systemEventSetKey = &#63;.
876             *
877             * @param systemEventId the primary key of the current system event
878             * @param groupId the group ID
879             * @param systemEventSetKey the system event set key
880             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
881             * @return the previous, current, and next system event
882             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
883             * @throws SystemException if a system exception occurred
884             */
885            @Override
886            public SystemEvent[] findByG_S_PrevAndNext(long systemEventId,
887                    long groupId, long systemEventSetKey,
888                    OrderByComparator orderByComparator)
889                    throws NoSuchSystemEventException, SystemException {
890                    SystemEvent systemEvent = findByPrimaryKey(systemEventId);
891    
892                    Session session = null;
893    
894                    try {
895                            session = openSession();
896    
897                            SystemEvent[] array = new SystemEventImpl[3];
898    
899                            array[0] = getByG_S_PrevAndNext(session, systemEvent, groupId,
900                                            systemEventSetKey, orderByComparator, true);
901    
902                            array[1] = systemEvent;
903    
904                            array[2] = getByG_S_PrevAndNext(session, systemEvent, groupId,
905                                            systemEventSetKey, orderByComparator, false);
906    
907                            return array;
908                    }
909                    catch (Exception e) {
910                            throw processException(e);
911                    }
912                    finally {
913                            closeSession(session);
914                    }
915            }
916    
917            protected SystemEvent getByG_S_PrevAndNext(Session session,
918                    SystemEvent systemEvent, long groupId, long systemEventSetKey,
919                    OrderByComparator orderByComparator, boolean previous) {
920                    StringBundler query = null;
921    
922                    if (orderByComparator != null) {
923                            query = new StringBundler(6 +
924                                            (orderByComparator.getOrderByFields().length * 6));
925                    }
926                    else {
927                            query = new StringBundler(3);
928                    }
929    
930                    query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
931    
932                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
933    
934                    query.append(_FINDER_COLUMN_G_S_SYSTEMEVENTSETKEY_2);
935    
936                    if (orderByComparator != null) {
937                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
938    
939                            if (orderByConditionFields.length > 0) {
940                                    query.append(WHERE_AND);
941                            }
942    
943                            for (int i = 0; i < orderByConditionFields.length; i++) {
944                                    query.append(_ORDER_BY_ENTITY_ALIAS);
945                                    query.append(orderByConditionFields[i]);
946    
947                                    if ((i + 1) < orderByConditionFields.length) {
948                                            if (orderByComparator.isAscending() ^ previous) {
949                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
950                                            }
951                                            else {
952                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
953                                            }
954                                    }
955                                    else {
956                                            if (orderByComparator.isAscending() ^ previous) {
957                                                    query.append(WHERE_GREATER_THAN);
958                                            }
959                                            else {
960                                                    query.append(WHERE_LESSER_THAN);
961                                            }
962                                    }
963                            }
964    
965                            query.append(ORDER_BY_CLAUSE);
966    
967                            String[] orderByFields = orderByComparator.getOrderByFields();
968    
969                            for (int i = 0; i < orderByFields.length; i++) {
970                                    query.append(_ORDER_BY_ENTITY_ALIAS);
971                                    query.append(orderByFields[i]);
972    
973                                    if ((i + 1) < orderByFields.length) {
974                                            if (orderByComparator.isAscending() ^ previous) {
975                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
976                                            }
977                                            else {
978                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
979                                            }
980                                    }
981                                    else {
982                                            if (orderByComparator.isAscending() ^ previous) {
983                                                    query.append(ORDER_BY_ASC);
984                                            }
985                                            else {
986                                                    query.append(ORDER_BY_DESC);
987                                            }
988                                    }
989                            }
990                    }
991                    else {
992                            query.append(SystemEventModelImpl.ORDER_BY_JPQL);
993                    }
994    
995                    String sql = query.toString();
996    
997                    Query q = session.createQuery(sql);
998    
999                    q.setFirstResult(0);
1000                    q.setMaxResults(2);
1001    
1002                    QueryPos qPos = QueryPos.getInstance(q);
1003    
1004                    qPos.add(groupId);
1005    
1006                    qPos.add(systemEventSetKey);
1007    
1008                    if (orderByComparator != null) {
1009                            Object[] values = orderByComparator.getOrderByConditionValues(systemEvent);
1010    
1011                            for (Object value : values) {
1012                                    qPos.add(value);
1013                            }
1014                    }
1015    
1016                    List<SystemEvent> list = q.list();
1017    
1018                    if (list.size() == 2) {
1019                            return list.get(1);
1020                    }
1021                    else {
1022                            return null;
1023                    }
1024            }
1025    
1026            /**
1027             * Removes all the system events where groupId = &#63; and systemEventSetKey = &#63; from the database.
1028             *
1029             * @param groupId the group ID
1030             * @param systemEventSetKey the system event set key
1031             * @throws SystemException if a system exception occurred
1032             */
1033            @Override
1034            public void removeByG_S(long groupId, long systemEventSetKey)
1035                    throws SystemException {
1036                    for (SystemEvent systemEvent : findByG_S(groupId, systemEventSetKey,
1037                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1038                            remove(systemEvent);
1039                    }
1040            }
1041    
1042            /**
1043             * Returns the number of system events where groupId = &#63; and systemEventSetKey = &#63;.
1044             *
1045             * @param groupId the group ID
1046             * @param systemEventSetKey the system event set key
1047             * @return the number of matching system events
1048             * @throws SystemException if a system exception occurred
1049             */
1050            @Override
1051            public int countByG_S(long groupId, long systemEventSetKey)
1052                    throws SystemException {
1053                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
1054    
1055                    Object[] finderArgs = new Object[] { groupId, systemEventSetKey };
1056    
1057                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1058                                    this);
1059    
1060                    if (count == null) {
1061                            StringBundler query = new StringBundler(3);
1062    
1063                            query.append(_SQL_COUNT_SYSTEMEVENT_WHERE);
1064    
1065                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1066    
1067                            query.append(_FINDER_COLUMN_G_S_SYSTEMEVENTSETKEY_2);
1068    
1069                            String sql = query.toString();
1070    
1071                            Session session = null;
1072    
1073                            try {
1074                                    session = openSession();
1075    
1076                                    Query q = session.createQuery(sql);
1077    
1078                                    QueryPos qPos = QueryPos.getInstance(q);
1079    
1080                                    qPos.add(groupId);
1081    
1082                                    qPos.add(systemEventSetKey);
1083    
1084                                    count = (Long)q.uniqueResult();
1085    
1086                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1087                            }
1088                            catch (Exception e) {
1089                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1090    
1091                                    throw processException(e);
1092                            }
1093                            finally {
1094                                    closeSession(session);
1095                            }
1096                    }
1097    
1098                    return count.intValue();
1099            }
1100    
1101            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "systemEvent.groupId = ? AND ";
1102            private static final String _FINDER_COLUMN_G_S_SYSTEMEVENTSETKEY_2 = "systemEvent.systemEventSetKey = ?";
1103            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
1104                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
1105                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
1106                            new String[] {
1107                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1108                                    
1109                            Integer.class.getName(), Integer.class.getName(),
1110                                    OrderByComparator.class.getName()
1111                            });
1112            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
1113                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
1114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
1115                            new String[] {
1116                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1117                            },
1118                            SystemEventModelImpl.GROUPID_COLUMN_BITMASK |
1119                            SystemEventModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1120                            SystemEventModelImpl.CLASSPK_COLUMN_BITMASK |
1121                            SystemEventModelImpl.CREATEDATE_COLUMN_BITMASK);
1122            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
1123                            SystemEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
1125                            new String[] {
1126                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1127                            });
1128    
1129            /**
1130             * Returns all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1131             *
1132             * @param groupId the group ID
1133             * @param classNameId the class name ID
1134             * @param classPK the class p k
1135             * @return the matching system events
1136             * @throws SystemException if a system exception occurred
1137             */
1138            @Override
1139            public List<SystemEvent> findByG_C_C(long groupId, long classNameId,
1140                    long classPK) throws SystemException {
1141                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
1142                            QueryUtil.ALL_POS, null);
1143            }
1144    
1145            /**
1146             * Returns a range of all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1147             *
1148             * <p>
1149             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
1150             * </p>
1151             *
1152             * @param groupId the group ID
1153             * @param classNameId the class name ID
1154             * @param classPK the class p k
1155             * @param start the lower bound of the range of system events
1156             * @param end the upper bound of the range of system events (not inclusive)
1157             * @return the range of matching system events
1158             * @throws SystemException if a system exception occurred
1159             */
1160            @Override
1161            public List<SystemEvent> findByG_C_C(long groupId, long classNameId,
1162                    long classPK, int start, int end) throws SystemException {
1163                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
1164            }
1165    
1166            /**
1167             * Returns an ordered range of all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1168             *
1169             * <p>
1170             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
1171             * </p>
1172             *
1173             * @param groupId the group ID
1174             * @param classNameId the class name ID
1175             * @param classPK the class p k
1176             * @param start the lower bound of the range of system events
1177             * @param end the upper bound of the range of system events (not inclusive)
1178             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1179             * @return the ordered range of matching system events
1180             * @throws SystemException if a system exception occurred
1181             */
1182            @Override
1183            public List<SystemEvent> findByG_C_C(long groupId, long classNameId,
1184                    long classPK, int start, int end, OrderByComparator orderByComparator)
1185                    throws SystemException {
1186                    boolean pagination = true;
1187                    FinderPath finderPath = null;
1188                    Object[] finderArgs = null;
1189    
1190                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1191                                    (orderByComparator == null)) {
1192                            pagination = false;
1193                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
1194                            finderArgs = new Object[] { groupId, classNameId, classPK };
1195                    }
1196                    else {
1197                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
1198                            finderArgs = new Object[] {
1199                                            groupId, classNameId, classPK,
1200                                            
1201                                            start, end, orderByComparator
1202                                    };
1203                    }
1204    
1205                    List<SystemEvent> list = (List<SystemEvent>)FinderCacheUtil.getResult(finderPath,
1206                                    finderArgs, this);
1207    
1208                    if ((list != null) && !list.isEmpty()) {
1209                            for (SystemEvent systemEvent : list) {
1210                                    if ((groupId != systemEvent.getGroupId()) ||
1211                                                    (classNameId != systemEvent.getClassNameId()) ||
1212                                                    (classPK != systemEvent.getClassPK())) {
1213                                            list = null;
1214    
1215                                            break;
1216                                    }
1217                            }
1218                    }
1219    
1220                    if (list == null) {
1221                            StringBundler query = null;
1222    
1223                            if (orderByComparator != null) {
1224                                    query = new StringBundler(5 +
1225                                                    (orderByComparator.getOrderByFields().length * 3));
1226                            }
1227                            else {
1228                                    query = new StringBundler(5);
1229                            }
1230    
1231                            query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
1232    
1233                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
1234    
1235                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
1236    
1237                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
1238    
1239                            if (orderByComparator != null) {
1240                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1241                                            orderByComparator);
1242                            }
1243                            else
1244                             if (pagination) {
1245                                    query.append(SystemEventModelImpl.ORDER_BY_JPQL);
1246                            }
1247    
1248                            String sql = query.toString();
1249    
1250                            Session session = null;
1251    
1252                            try {
1253                                    session = openSession();
1254    
1255                                    Query q = session.createQuery(sql);
1256    
1257                                    QueryPos qPos = QueryPos.getInstance(q);
1258    
1259                                    qPos.add(groupId);
1260    
1261                                    qPos.add(classNameId);
1262    
1263                                    qPos.add(classPK);
1264    
1265                                    if (!pagination) {
1266                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
1267                                                            start, end, false);
1268    
1269                                            Collections.sort(list);
1270    
1271                                            list = new UnmodifiableList<SystemEvent>(list);
1272                                    }
1273                                    else {
1274                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
1275                                                            start, end);
1276                                    }
1277    
1278                                    cacheResult(list);
1279    
1280                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1281                            }
1282                            catch (Exception e) {
1283                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1284    
1285                                    throw processException(e);
1286                            }
1287                            finally {
1288                                    closeSession(session);
1289                            }
1290                    }
1291    
1292                    return list;
1293            }
1294    
1295            /**
1296             * Returns the first system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1297             *
1298             * @param groupId the group ID
1299             * @param classNameId the class name ID
1300             * @param classPK the class p k
1301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1302             * @return the first matching system event
1303             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
1304             * @throws SystemException if a system exception occurred
1305             */
1306            @Override
1307            public SystemEvent findByG_C_C_First(long groupId, long classNameId,
1308                    long classPK, OrderByComparator orderByComparator)
1309                    throws NoSuchSystemEventException, SystemException {
1310                    SystemEvent systemEvent = fetchByG_C_C_First(groupId, classNameId,
1311                                    classPK, orderByComparator);
1312    
1313                    if (systemEvent != null) {
1314                            return systemEvent;
1315                    }
1316    
1317                    StringBundler msg = new StringBundler(8);
1318    
1319                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1320    
1321                    msg.append("groupId=");
1322                    msg.append(groupId);
1323    
1324                    msg.append(", classNameId=");
1325                    msg.append(classNameId);
1326    
1327                    msg.append(", classPK=");
1328                    msg.append(classPK);
1329    
1330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1331    
1332                    throw new NoSuchSystemEventException(msg.toString());
1333            }
1334    
1335            /**
1336             * Returns the first system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1337             *
1338             * @param groupId the group ID
1339             * @param classNameId the class name ID
1340             * @param classPK the class p k
1341             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1342             * @return the first matching system event, or <code>null</code> if a matching system event could not be found
1343             * @throws SystemException if a system exception occurred
1344             */
1345            @Override
1346            public SystemEvent fetchByG_C_C_First(long groupId, long classNameId,
1347                    long classPK, OrderByComparator orderByComparator)
1348                    throws SystemException {
1349                    List<SystemEvent> list = findByG_C_C(groupId, classNameId, classPK, 0,
1350                                    1, orderByComparator);
1351    
1352                    if (!list.isEmpty()) {
1353                            return list.get(0);
1354                    }
1355    
1356                    return null;
1357            }
1358    
1359            /**
1360             * Returns the last system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1361             *
1362             * @param groupId the group ID
1363             * @param classNameId the class name ID
1364             * @param classPK the class p k
1365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1366             * @return the last matching system event
1367             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
1368             * @throws SystemException if a system exception occurred
1369             */
1370            @Override
1371            public SystemEvent findByG_C_C_Last(long groupId, long classNameId,
1372                    long classPK, OrderByComparator orderByComparator)
1373                    throws NoSuchSystemEventException, SystemException {
1374                    SystemEvent systemEvent = fetchByG_C_C_Last(groupId, classNameId,
1375                                    classPK, orderByComparator);
1376    
1377                    if (systemEvent != null) {
1378                            return systemEvent;
1379                    }
1380    
1381                    StringBundler msg = new StringBundler(8);
1382    
1383                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1384    
1385                    msg.append("groupId=");
1386                    msg.append(groupId);
1387    
1388                    msg.append(", classNameId=");
1389                    msg.append(classNameId);
1390    
1391                    msg.append(", classPK=");
1392                    msg.append(classPK);
1393    
1394                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1395    
1396                    throw new NoSuchSystemEventException(msg.toString());
1397            }
1398    
1399            /**
1400             * Returns the last system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1401             *
1402             * @param groupId the group ID
1403             * @param classNameId the class name ID
1404             * @param classPK the class p k
1405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1406             * @return the last matching system event, or <code>null</code> if a matching system event could not be found
1407             * @throws SystemException if a system exception occurred
1408             */
1409            @Override
1410            public SystemEvent fetchByG_C_C_Last(long groupId, long classNameId,
1411                    long classPK, OrderByComparator orderByComparator)
1412                    throws SystemException {
1413                    int count = countByG_C_C(groupId, classNameId, classPK);
1414    
1415                    if (count == 0) {
1416                            return null;
1417                    }
1418    
1419                    List<SystemEvent> list = findByG_C_C(groupId, classNameId, classPK,
1420                                    count - 1, count, orderByComparator);
1421    
1422                    if (!list.isEmpty()) {
1423                            return list.get(0);
1424                    }
1425    
1426                    return null;
1427            }
1428    
1429            /**
1430             * Returns the system events before and after the current system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1431             *
1432             * @param systemEventId the primary key of the current system event
1433             * @param groupId the group ID
1434             * @param classNameId the class name ID
1435             * @param classPK the class p k
1436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1437             * @return the previous, current, and next system event
1438             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
1439             * @throws SystemException if a system exception occurred
1440             */
1441            @Override
1442            public SystemEvent[] findByG_C_C_PrevAndNext(long systemEventId,
1443                    long groupId, long classNameId, long classPK,
1444                    OrderByComparator orderByComparator)
1445                    throws NoSuchSystemEventException, SystemException {
1446                    SystemEvent systemEvent = findByPrimaryKey(systemEventId);
1447    
1448                    Session session = null;
1449    
1450                    try {
1451                            session = openSession();
1452    
1453                            SystemEvent[] array = new SystemEventImpl[3];
1454    
1455                            array[0] = getByG_C_C_PrevAndNext(session, systemEvent, groupId,
1456                                            classNameId, classPK, orderByComparator, true);
1457    
1458                            array[1] = systemEvent;
1459    
1460                            array[2] = getByG_C_C_PrevAndNext(session, systemEvent, groupId,
1461                                            classNameId, classPK, orderByComparator, false);
1462    
1463                            return array;
1464                    }
1465                    catch (Exception e) {
1466                            throw processException(e);
1467                    }
1468                    finally {
1469                            closeSession(session);
1470                    }
1471            }
1472    
1473            protected SystemEvent getByG_C_C_PrevAndNext(Session session,
1474                    SystemEvent systemEvent, long groupId, long classNameId, long classPK,
1475                    OrderByComparator orderByComparator, boolean previous) {
1476                    StringBundler query = null;
1477    
1478                    if (orderByComparator != null) {
1479                            query = new StringBundler(6 +
1480                                            (orderByComparator.getOrderByFields().length * 6));
1481                    }
1482                    else {
1483                            query = new StringBundler(3);
1484                    }
1485    
1486                    query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
1487    
1488                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
1489    
1490                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
1491    
1492                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
1493    
1494                    if (orderByComparator != null) {
1495                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1496    
1497                            if (orderByConditionFields.length > 0) {
1498                                    query.append(WHERE_AND);
1499                            }
1500    
1501                            for (int i = 0; i < orderByConditionFields.length; i++) {
1502                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1503                                    query.append(orderByConditionFields[i]);
1504    
1505                                    if ((i + 1) < orderByConditionFields.length) {
1506                                            if (orderByComparator.isAscending() ^ previous) {
1507                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1508                                            }
1509                                            else {
1510                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1511                                            }
1512                                    }
1513                                    else {
1514                                            if (orderByComparator.isAscending() ^ previous) {
1515                                                    query.append(WHERE_GREATER_THAN);
1516                                            }
1517                                            else {
1518                                                    query.append(WHERE_LESSER_THAN);
1519                                            }
1520                                    }
1521                            }
1522    
1523                            query.append(ORDER_BY_CLAUSE);
1524    
1525                            String[] orderByFields = orderByComparator.getOrderByFields();
1526    
1527                            for (int i = 0; i < orderByFields.length; i++) {
1528                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1529                                    query.append(orderByFields[i]);
1530    
1531                                    if ((i + 1) < orderByFields.length) {
1532                                            if (orderByComparator.isAscending() ^ previous) {
1533                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1534                                            }
1535                                            else {
1536                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1537                                            }
1538                                    }
1539                                    else {
1540                                            if (orderByComparator.isAscending() ^ previous) {
1541                                                    query.append(ORDER_BY_ASC);
1542                                            }
1543                                            else {
1544                                                    query.append(ORDER_BY_DESC);
1545                                            }
1546                                    }
1547                            }
1548                    }
1549                    else {
1550                            query.append(SystemEventModelImpl.ORDER_BY_JPQL);
1551                    }
1552    
1553                    String sql = query.toString();
1554    
1555                    Query q = session.createQuery(sql);
1556    
1557                    q.setFirstResult(0);
1558                    q.setMaxResults(2);
1559    
1560                    QueryPos qPos = QueryPos.getInstance(q);
1561    
1562                    qPos.add(groupId);
1563    
1564                    qPos.add(classNameId);
1565    
1566                    qPos.add(classPK);
1567    
1568                    if (orderByComparator != null) {
1569                            Object[] values = orderByComparator.getOrderByConditionValues(systemEvent);
1570    
1571                            for (Object value : values) {
1572                                    qPos.add(value);
1573                            }
1574                    }
1575    
1576                    List<SystemEvent> list = q.list();
1577    
1578                    if (list.size() == 2) {
1579                            return list.get(1);
1580                    }
1581                    else {
1582                            return null;
1583                    }
1584            }
1585    
1586            /**
1587             * Removes all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1588             *
1589             * @param groupId the group ID
1590             * @param classNameId the class name ID
1591             * @param classPK the class p k
1592             * @throws SystemException if a system exception occurred
1593             */
1594            @Override
1595            public void removeByG_C_C(long groupId, long classNameId, long classPK)
1596                    throws SystemException {
1597                    for (SystemEvent systemEvent : findByG_C_C(groupId, classNameId,
1598                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1599                            remove(systemEvent);
1600                    }
1601            }
1602    
1603            /**
1604             * Returns the number of system events where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1605             *
1606             * @param groupId the group ID
1607             * @param classNameId the class name ID
1608             * @param classPK the class p k
1609             * @return the number of matching system events
1610             * @throws SystemException if a system exception occurred
1611             */
1612            @Override
1613            public int countByG_C_C(long groupId, long classNameId, long classPK)
1614                    throws SystemException {
1615                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C;
1616    
1617                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
1618    
1619                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1620                                    this);
1621    
1622                    if (count == null) {
1623                            StringBundler query = new StringBundler(4);
1624    
1625                            query.append(_SQL_COUNT_SYSTEMEVENT_WHERE);
1626    
1627                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
1628    
1629                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
1630    
1631                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
1632    
1633                            String sql = query.toString();
1634    
1635                            Session session = null;
1636    
1637                            try {
1638                                    session = openSession();
1639    
1640                                    Query q = session.createQuery(sql);
1641    
1642                                    QueryPos qPos = QueryPos.getInstance(q);
1643    
1644                                    qPos.add(groupId);
1645    
1646                                    qPos.add(classNameId);
1647    
1648                                    qPos.add(classPK);
1649    
1650                                    count = (Long)q.uniqueResult();
1651    
1652                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1653                            }
1654                            catch (Exception e) {
1655                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1656    
1657                                    throw processException(e);
1658                            }
1659                            finally {
1660                                    closeSession(session);
1661                            }
1662                    }
1663    
1664                    return count.intValue();
1665            }
1666    
1667            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "systemEvent.groupId = ? AND ";
1668            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "systemEvent.classNameId = ? AND ";
1669            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "systemEvent.classPK = ?";
1670            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_T = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
1671                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
1672                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C_T",
1673                            new String[] {
1674                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1675                                    Integer.class.getName(),
1676                                    
1677                            Integer.class.getName(), Integer.class.getName(),
1678                                    OrderByComparator.class.getName()
1679                            });
1680            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T =
1681                    new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
1682                            SystemEventModelImpl.FINDER_CACHE_ENABLED, SystemEventImpl.class,
1683                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C_T",
1684                            new String[] {
1685                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1686                                    Integer.class.getName()
1687                            },
1688                            SystemEventModelImpl.GROUPID_COLUMN_BITMASK |
1689                            SystemEventModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1690                            SystemEventModelImpl.CLASSPK_COLUMN_BITMASK |
1691                            SystemEventModelImpl.TYPE_COLUMN_BITMASK |
1692                            SystemEventModelImpl.CREATEDATE_COLUMN_BITMASK);
1693            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_T = new FinderPath(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
1694                            SystemEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1695                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_T",
1696                            new String[] {
1697                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1698                                    Integer.class.getName()
1699                            });
1700    
1701            /**
1702             * Returns all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1703             *
1704             * @param groupId the group ID
1705             * @param classNameId the class name ID
1706             * @param classPK the class p k
1707             * @param type the type
1708             * @return the matching system events
1709             * @throws SystemException if a system exception occurred
1710             */
1711            @Override
1712            public List<SystemEvent> findByG_C_C_T(long groupId, long classNameId,
1713                    long classPK, int type) throws SystemException {
1714                    return findByG_C_C_T(groupId, classNameId, classPK, type,
1715                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1716            }
1717    
1718            /**
1719             * Returns a range of all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1720             *
1721             * <p>
1722             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
1723             * </p>
1724             *
1725             * @param groupId the group ID
1726             * @param classNameId the class name ID
1727             * @param classPK the class p k
1728             * @param type the type
1729             * @param start the lower bound of the range of system events
1730             * @param end the upper bound of the range of system events (not inclusive)
1731             * @return the range of matching system events
1732             * @throws SystemException if a system exception occurred
1733             */
1734            @Override
1735            public List<SystemEvent> findByG_C_C_T(long groupId, long classNameId,
1736                    long classPK, int type, int start, int end) throws SystemException {
1737                    return findByG_C_C_T(groupId, classNameId, classPK, type, start, end,
1738                            null);
1739            }
1740    
1741            /**
1742             * Returns an ordered range of all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1743             *
1744             * <p>
1745             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
1746             * </p>
1747             *
1748             * @param groupId the group ID
1749             * @param classNameId the class name ID
1750             * @param classPK the class p k
1751             * @param type the type
1752             * @param start the lower bound of the range of system events
1753             * @param end the upper bound of the range of system events (not inclusive)
1754             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1755             * @return the ordered range of matching system events
1756             * @throws SystemException if a system exception occurred
1757             */
1758            @Override
1759            public List<SystemEvent> findByG_C_C_T(long groupId, long classNameId,
1760                    long classPK, int type, int start, int end,
1761                    OrderByComparator orderByComparator) throws SystemException {
1762                    boolean pagination = true;
1763                    FinderPath finderPath = null;
1764                    Object[] finderArgs = null;
1765    
1766                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1767                                    (orderByComparator == null)) {
1768                            pagination = false;
1769                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T;
1770                            finderArgs = new Object[] { groupId, classNameId, classPK, type };
1771                    }
1772                    else {
1773                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_T;
1774                            finderArgs = new Object[] {
1775                                            groupId, classNameId, classPK, type,
1776                                            
1777                                            start, end, orderByComparator
1778                                    };
1779                    }
1780    
1781                    List<SystemEvent> list = (List<SystemEvent>)FinderCacheUtil.getResult(finderPath,
1782                                    finderArgs, this);
1783    
1784                    if ((list != null) && !list.isEmpty()) {
1785                            for (SystemEvent systemEvent : list) {
1786                                    if ((groupId != systemEvent.getGroupId()) ||
1787                                                    (classNameId != systemEvent.getClassNameId()) ||
1788                                                    (classPK != systemEvent.getClassPK()) ||
1789                                                    (type != systemEvent.getType())) {
1790                                            list = null;
1791    
1792                                            break;
1793                                    }
1794                            }
1795                    }
1796    
1797                    if (list == null) {
1798                            StringBundler query = null;
1799    
1800                            if (orderByComparator != null) {
1801                                    query = new StringBundler(6 +
1802                                                    (orderByComparator.getOrderByFields().length * 3));
1803                            }
1804                            else {
1805                                    query = new StringBundler(6);
1806                            }
1807    
1808                            query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
1809    
1810                            query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
1811    
1812                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
1813    
1814                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
1815    
1816                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2);
1817    
1818                            if (orderByComparator != null) {
1819                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1820                                            orderByComparator);
1821                            }
1822                            else
1823                             if (pagination) {
1824                                    query.append(SystemEventModelImpl.ORDER_BY_JPQL);
1825                            }
1826    
1827                            String sql = query.toString();
1828    
1829                            Session session = null;
1830    
1831                            try {
1832                                    session = openSession();
1833    
1834                                    Query q = session.createQuery(sql);
1835    
1836                                    QueryPos qPos = QueryPos.getInstance(q);
1837    
1838                                    qPos.add(groupId);
1839    
1840                                    qPos.add(classNameId);
1841    
1842                                    qPos.add(classPK);
1843    
1844                                    qPos.add(type);
1845    
1846                                    if (!pagination) {
1847                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
1848                                                            start, end, false);
1849    
1850                                            Collections.sort(list);
1851    
1852                                            list = new UnmodifiableList<SystemEvent>(list);
1853                                    }
1854                                    else {
1855                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
1856                                                            start, end);
1857                                    }
1858    
1859                                    cacheResult(list);
1860    
1861                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1862                            }
1863                            catch (Exception e) {
1864                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1865    
1866                                    throw processException(e);
1867                            }
1868                            finally {
1869                                    closeSession(session);
1870                            }
1871                    }
1872    
1873                    return list;
1874            }
1875    
1876            /**
1877             * Returns the first system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1878             *
1879             * @param groupId the group ID
1880             * @param classNameId the class name ID
1881             * @param classPK the class p k
1882             * @param type the type
1883             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1884             * @return the first matching system event
1885             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
1886             * @throws SystemException if a system exception occurred
1887             */
1888            @Override
1889            public SystemEvent findByG_C_C_T_First(long groupId, long classNameId,
1890                    long classPK, int type, OrderByComparator orderByComparator)
1891                    throws NoSuchSystemEventException, SystemException {
1892                    SystemEvent systemEvent = fetchByG_C_C_T_First(groupId, classNameId,
1893                                    classPK, type, orderByComparator);
1894    
1895                    if (systemEvent != null) {
1896                            return systemEvent;
1897                    }
1898    
1899                    StringBundler msg = new StringBundler(10);
1900    
1901                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1902    
1903                    msg.append("groupId=");
1904                    msg.append(groupId);
1905    
1906                    msg.append(", classNameId=");
1907                    msg.append(classNameId);
1908    
1909                    msg.append(", classPK=");
1910                    msg.append(classPK);
1911    
1912                    msg.append(", type=");
1913                    msg.append(type);
1914    
1915                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1916    
1917                    throw new NoSuchSystemEventException(msg.toString());
1918            }
1919    
1920            /**
1921             * Returns the first system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1922             *
1923             * @param groupId the group ID
1924             * @param classNameId the class name ID
1925             * @param classPK the class p k
1926             * @param type the type
1927             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1928             * @return the first matching system event, or <code>null</code> if a matching system event could not be found
1929             * @throws SystemException if a system exception occurred
1930             */
1931            @Override
1932            public SystemEvent fetchByG_C_C_T_First(long groupId, long classNameId,
1933                    long classPK, int type, OrderByComparator orderByComparator)
1934                    throws SystemException {
1935                    List<SystemEvent> list = findByG_C_C_T(groupId, classNameId, classPK,
1936                                    type, 0, 1, orderByComparator);
1937    
1938                    if (!list.isEmpty()) {
1939                            return list.get(0);
1940                    }
1941    
1942                    return null;
1943            }
1944    
1945            /**
1946             * Returns the last system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1947             *
1948             * @param groupId the group ID
1949             * @param classNameId the class name ID
1950             * @param classPK the class p k
1951             * @param type the type
1952             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1953             * @return the last matching system event
1954             * @throws com.liferay.portal.NoSuchSystemEventException if a matching system event could not be found
1955             * @throws SystemException if a system exception occurred
1956             */
1957            @Override
1958            public SystemEvent findByG_C_C_T_Last(long groupId, long classNameId,
1959                    long classPK, int type, OrderByComparator orderByComparator)
1960                    throws NoSuchSystemEventException, SystemException {
1961                    SystemEvent systemEvent = fetchByG_C_C_T_Last(groupId, classNameId,
1962                                    classPK, type, orderByComparator);
1963    
1964                    if (systemEvent != null) {
1965                            return systemEvent;
1966                    }
1967    
1968                    StringBundler msg = new StringBundler(10);
1969    
1970                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1971    
1972                    msg.append("groupId=");
1973                    msg.append(groupId);
1974    
1975                    msg.append(", classNameId=");
1976                    msg.append(classNameId);
1977    
1978                    msg.append(", classPK=");
1979                    msg.append(classPK);
1980    
1981                    msg.append(", type=");
1982                    msg.append(type);
1983    
1984                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1985    
1986                    throw new NoSuchSystemEventException(msg.toString());
1987            }
1988    
1989            /**
1990             * Returns the last system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1991             *
1992             * @param groupId the group ID
1993             * @param classNameId the class name ID
1994             * @param classPK the class p k
1995             * @param type the type
1996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1997             * @return the last matching system event, or <code>null</code> if a matching system event could not be found
1998             * @throws SystemException if a system exception occurred
1999             */
2000            @Override
2001            public SystemEvent fetchByG_C_C_T_Last(long groupId, long classNameId,
2002                    long classPK, int type, OrderByComparator orderByComparator)
2003                    throws SystemException {
2004                    int count = countByG_C_C_T(groupId, classNameId, classPK, type);
2005    
2006                    if (count == 0) {
2007                            return null;
2008                    }
2009    
2010                    List<SystemEvent> list = findByG_C_C_T(groupId, classNameId, classPK,
2011                                    type, count - 1, count, orderByComparator);
2012    
2013                    if (!list.isEmpty()) {
2014                            return list.get(0);
2015                    }
2016    
2017                    return null;
2018            }
2019    
2020            /**
2021             * Returns the system events before and after the current system event in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
2022             *
2023             * @param systemEventId the primary key of the current system event
2024             * @param groupId the group ID
2025             * @param classNameId the class name ID
2026             * @param classPK the class p k
2027             * @param type the type
2028             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2029             * @return the previous, current, and next system event
2030             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
2031             * @throws SystemException if a system exception occurred
2032             */
2033            @Override
2034            public SystemEvent[] findByG_C_C_T_PrevAndNext(long systemEventId,
2035                    long groupId, long classNameId, long classPK, int type,
2036                    OrderByComparator orderByComparator)
2037                    throws NoSuchSystemEventException, SystemException {
2038                    SystemEvent systemEvent = findByPrimaryKey(systemEventId);
2039    
2040                    Session session = null;
2041    
2042                    try {
2043                            session = openSession();
2044    
2045                            SystemEvent[] array = new SystemEventImpl[3];
2046    
2047                            array[0] = getByG_C_C_T_PrevAndNext(session, systemEvent, groupId,
2048                                            classNameId, classPK, type, orderByComparator, true);
2049    
2050                            array[1] = systemEvent;
2051    
2052                            array[2] = getByG_C_C_T_PrevAndNext(session, systemEvent, groupId,
2053                                            classNameId, classPK, type, orderByComparator, false);
2054    
2055                            return array;
2056                    }
2057                    catch (Exception e) {
2058                            throw processException(e);
2059                    }
2060                    finally {
2061                            closeSession(session);
2062                    }
2063            }
2064    
2065            protected SystemEvent getByG_C_C_T_PrevAndNext(Session session,
2066                    SystemEvent systemEvent, long groupId, long classNameId, long classPK,
2067                    int type, OrderByComparator orderByComparator, boolean previous) {
2068                    StringBundler query = null;
2069    
2070                    if (orderByComparator != null) {
2071                            query = new StringBundler(6 +
2072                                            (orderByComparator.getOrderByFields().length * 6));
2073                    }
2074                    else {
2075                            query = new StringBundler(3);
2076                    }
2077    
2078                    query.append(_SQL_SELECT_SYSTEMEVENT_WHERE);
2079    
2080                    query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
2081    
2082                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
2083    
2084                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
2085    
2086                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2);
2087    
2088                    if (orderByComparator != null) {
2089                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2090    
2091                            if (orderByConditionFields.length > 0) {
2092                                    query.append(WHERE_AND);
2093                            }
2094    
2095                            for (int i = 0; i < orderByConditionFields.length; i++) {
2096                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2097                                    query.append(orderByConditionFields[i]);
2098    
2099                                    if ((i + 1) < orderByConditionFields.length) {
2100                                            if (orderByComparator.isAscending() ^ previous) {
2101                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2102                                            }
2103                                            else {
2104                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2105                                            }
2106                                    }
2107                                    else {
2108                                            if (orderByComparator.isAscending() ^ previous) {
2109                                                    query.append(WHERE_GREATER_THAN);
2110                                            }
2111                                            else {
2112                                                    query.append(WHERE_LESSER_THAN);
2113                                            }
2114                                    }
2115                            }
2116    
2117                            query.append(ORDER_BY_CLAUSE);
2118    
2119                            String[] orderByFields = orderByComparator.getOrderByFields();
2120    
2121                            for (int i = 0; i < orderByFields.length; i++) {
2122                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2123                                    query.append(orderByFields[i]);
2124    
2125                                    if ((i + 1) < orderByFields.length) {
2126                                            if (orderByComparator.isAscending() ^ previous) {
2127                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2128                                            }
2129                                            else {
2130                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2131                                            }
2132                                    }
2133                                    else {
2134                                            if (orderByComparator.isAscending() ^ previous) {
2135                                                    query.append(ORDER_BY_ASC);
2136                                            }
2137                                            else {
2138                                                    query.append(ORDER_BY_DESC);
2139                                            }
2140                                    }
2141                            }
2142                    }
2143                    else {
2144                            query.append(SystemEventModelImpl.ORDER_BY_JPQL);
2145                    }
2146    
2147                    String sql = query.toString();
2148    
2149                    Query q = session.createQuery(sql);
2150    
2151                    q.setFirstResult(0);
2152                    q.setMaxResults(2);
2153    
2154                    QueryPos qPos = QueryPos.getInstance(q);
2155    
2156                    qPos.add(groupId);
2157    
2158                    qPos.add(classNameId);
2159    
2160                    qPos.add(classPK);
2161    
2162                    qPos.add(type);
2163    
2164                    if (orderByComparator != null) {
2165                            Object[] values = orderByComparator.getOrderByConditionValues(systemEvent);
2166    
2167                            for (Object value : values) {
2168                                    qPos.add(value);
2169                            }
2170                    }
2171    
2172                    List<SystemEvent> list = q.list();
2173    
2174                    if (list.size() == 2) {
2175                            return list.get(1);
2176                    }
2177                    else {
2178                            return null;
2179                    }
2180            }
2181    
2182            /**
2183             * Removes all the system events where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
2184             *
2185             * @param groupId the group ID
2186             * @param classNameId the class name ID
2187             * @param classPK the class p k
2188             * @param type the type
2189             * @throws SystemException if a system exception occurred
2190             */
2191            @Override
2192            public void removeByG_C_C_T(long groupId, long classNameId, long classPK,
2193                    int type) throws SystemException {
2194                    for (SystemEvent systemEvent : findByG_C_C_T(groupId, classNameId,
2195                                    classPK, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2196                            remove(systemEvent);
2197                    }
2198            }
2199    
2200            /**
2201             * Returns the number of system events where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
2202             *
2203             * @param groupId the group ID
2204             * @param classNameId the class name ID
2205             * @param classPK the class p k
2206             * @param type the type
2207             * @return the number of matching system events
2208             * @throws SystemException if a system exception occurred
2209             */
2210            @Override
2211            public int countByG_C_C_T(long groupId, long classNameId, long classPK,
2212                    int type) throws SystemException {
2213                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_T;
2214    
2215                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK, type };
2216    
2217                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2218                                    this);
2219    
2220                    if (count == null) {
2221                            StringBundler query = new StringBundler(5);
2222    
2223                            query.append(_SQL_COUNT_SYSTEMEVENT_WHERE);
2224    
2225                            query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
2226    
2227                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
2228    
2229                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
2230    
2231                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2);
2232    
2233                            String sql = query.toString();
2234    
2235                            Session session = null;
2236    
2237                            try {
2238                                    session = openSession();
2239    
2240                                    Query q = session.createQuery(sql);
2241    
2242                                    QueryPos qPos = QueryPos.getInstance(q);
2243    
2244                                    qPos.add(groupId);
2245    
2246                                    qPos.add(classNameId);
2247    
2248                                    qPos.add(classPK);
2249    
2250                                    qPos.add(type);
2251    
2252                                    count = (Long)q.uniqueResult();
2253    
2254                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2255                            }
2256                            catch (Exception e) {
2257                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2258    
2259                                    throw processException(e);
2260                            }
2261                            finally {
2262                                    closeSession(session);
2263                            }
2264                    }
2265    
2266                    return count.intValue();
2267            }
2268    
2269            private static final String _FINDER_COLUMN_G_C_C_T_GROUPID_2 = "systemEvent.groupId = ? AND ";
2270            private static final String _FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2 = "systemEvent.classNameId = ? AND ";
2271            private static final String _FINDER_COLUMN_G_C_C_T_CLASSPK_2 = "systemEvent.classPK = ? AND ";
2272            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_2 = "systemEvent.type = ?";
2273    
2274            public SystemEventPersistenceImpl() {
2275                    setModelClass(SystemEvent.class);
2276            }
2277    
2278            /**
2279             * Caches the system event in the entity cache if it is enabled.
2280             *
2281             * @param systemEvent the system event
2282             */
2283            @Override
2284            public void cacheResult(SystemEvent systemEvent) {
2285                    EntityCacheUtil.putResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2286                            SystemEventImpl.class, systemEvent.getPrimaryKey(), systemEvent);
2287    
2288                    systemEvent.resetOriginalValues();
2289            }
2290    
2291            /**
2292             * Caches the system events in the entity cache if it is enabled.
2293             *
2294             * @param systemEvents the system events
2295             */
2296            @Override
2297            public void cacheResult(List<SystemEvent> systemEvents) {
2298                    for (SystemEvent systemEvent : systemEvents) {
2299                            if (EntityCacheUtil.getResult(
2300                                                    SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2301                                                    SystemEventImpl.class, systemEvent.getPrimaryKey()) == null) {
2302                                    cacheResult(systemEvent);
2303                            }
2304                            else {
2305                                    systemEvent.resetOriginalValues();
2306                            }
2307                    }
2308            }
2309    
2310            /**
2311             * Clears the cache for all system events.
2312             *
2313             * <p>
2314             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2315             * </p>
2316             */
2317            @Override
2318            public void clearCache() {
2319                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2320                            CacheRegistryUtil.clear(SystemEventImpl.class.getName());
2321                    }
2322    
2323                    EntityCacheUtil.clearCache(SystemEventImpl.class.getName());
2324    
2325                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2326                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2327                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2328            }
2329    
2330            /**
2331             * Clears the cache for the system event.
2332             *
2333             * <p>
2334             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2335             * </p>
2336             */
2337            @Override
2338            public void clearCache(SystemEvent systemEvent) {
2339                    EntityCacheUtil.removeResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2340                            SystemEventImpl.class, systemEvent.getPrimaryKey());
2341    
2342                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2344            }
2345    
2346            @Override
2347            public void clearCache(List<SystemEvent> systemEvents) {
2348                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2349                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2350    
2351                    for (SystemEvent systemEvent : systemEvents) {
2352                            EntityCacheUtil.removeResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2353                                    SystemEventImpl.class, systemEvent.getPrimaryKey());
2354                    }
2355            }
2356    
2357            /**
2358             * Creates a new system event with the primary key. Does not add the system event to the database.
2359             *
2360             * @param systemEventId the primary key for the new system event
2361             * @return the new system event
2362             */
2363            @Override
2364            public SystemEvent create(long systemEventId) {
2365                    SystemEvent systemEvent = new SystemEventImpl();
2366    
2367                    systemEvent.setNew(true);
2368                    systemEvent.setPrimaryKey(systemEventId);
2369    
2370                    return systemEvent;
2371            }
2372    
2373            /**
2374             * Removes the system event with the primary key from the database. Also notifies the appropriate model listeners.
2375             *
2376             * @param systemEventId the primary key of the system event
2377             * @return the system event that was removed
2378             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
2379             * @throws SystemException if a system exception occurred
2380             */
2381            @Override
2382            public SystemEvent remove(long systemEventId)
2383                    throws NoSuchSystemEventException, SystemException {
2384                    return remove((Serializable)systemEventId);
2385            }
2386    
2387            /**
2388             * Removes the system event with the primary key from the database. Also notifies the appropriate model listeners.
2389             *
2390             * @param primaryKey the primary key of the system event
2391             * @return the system event that was removed
2392             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
2393             * @throws SystemException if a system exception occurred
2394             */
2395            @Override
2396            public SystemEvent remove(Serializable primaryKey)
2397                    throws NoSuchSystemEventException, SystemException {
2398                    Session session = null;
2399    
2400                    try {
2401                            session = openSession();
2402    
2403                            SystemEvent systemEvent = (SystemEvent)session.get(SystemEventImpl.class,
2404                                            primaryKey);
2405    
2406                            if (systemEvent == null) {
2407                                    if (_log.isWarnEnabled()) {
2408                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2409                                    }
2410    
2411                                    throw new NoSuchSystemEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2412                                            primaryKey);
2413                            }
2414    
2415                            return remove(systemEvent);
2416                    }
2417                    catch (NoSuchSystemEventException nsee) {
2418                            throw nsee;
2419                    }
2420                    catch (Exception e) {
2421                            throw processException(e);
2422                    }
2423                    finally {
2424                            closeSession(session);
2425                    }
2426            }
2427    
2428            @Override
2429            protected SystemEvent removeImpl(SystemEvent systemEvent)
2430                    throws SystemException {
2431                    systemEvent = toUnwrappedModel(systemEvent);
2432    
2433                    Session session = null;
2434    
2435                    try {
2436                            session = openSession();
2437    
2438                            if (!session.contains(systemEvent)) {
2439                                    systemEvent = (SystemEvent)session.get(SystemEventImpl.class,
2440                                                    systemEvent.getPrimaryKeyObj());
2441                            }
2442    
2443                            if (systemEvent != null) {
2444                                    session.delete(systemEvent);
2445                            }
2446                    }
2447                    catch (Exception e) {
2448                            throw processException(e);
2449                    }
2450                    finally {
2451                            closeSession(session);
2452                    }
2453    
2454                    if (systemEvent != null) {
2455                            clearCache(systemEvent);
2456                    }
2457    
2458                    return systemEvent;
2459            }
2460    
2461            @Override
2462            public SystemEvent updateImpl(
2463                    com.liferay.portal.model.SystemEvent systemEvent)
2464                    throws SystemException {
2465                    systemEvent = toUnwrappedModel(systemEvent);
2466    
2467                    boolean isNew = systemEvent.isNew();
2468    
2469                    SystemEventModelImpl systemEventModelImpl = (SystemEventModelImpl)systemEvent;
2470    
2471                    Session session = null;
2472    
2473                    try {
2474                            session = openSession();
2475    
2476                            if (systemEvent.isNew()) {
2477                                    session.save(systemEvent);
2478    
2479                                    systemEvent.setNew(false);
2480                            }
2481                            else {
2482                                    session.merge(systemEvent);
2483                            }
2484                    }
2485                    catch (Exception e) {
2486                            throw processException(e);
2487                    }
2488                    finally {
2489                            closeSession(session);
2490                    }
2491    
2492                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2493    
2494                    if (isNew || !SystemEventModelImpl.COLUMN_BITMASK_ENABLED) {
2495                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2496                    }
2497    
2498                    else {
2499                            if ((systemEventModelImpl.getColumnBitmask() &
2500                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2501                                    Object[] args = new Object[] {
2502                                                    systemEventModelImpl.getOriginalGroupId()
2503                                            };
2504    
2505                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2506                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2507                                            args);
2508    
2509                                    args = new Object[] { systemEventModelImpl.getGroupId() };
2510    
2511                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2512                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2513                                            args);
2514                            }
2515    
2516                            if ((systemEventModelImpl.getColumnBitmask() &
2517                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
2518                                    Object[] args = new Object[] {
2519                                                    systemEventModelImpl.getOriginalGroupId(),
2520                                                    systemEventModelImpl.getOriginalSystemEventSetKey()
2521                                            };
2522    
2523                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
2524                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
2525                                            args);
2526    
2527                                    args = new Object[] {
2528                                                    systemEventModelImpl.getGroupId(),
2529                                                    systemEventModelImpl.getSystemEventSetKey()
2530                                            };
2531    
2532                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
2533                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
2534                                            args);
2535                            }
2536    
2537                            if ((systemEventModelImpl.getColumnBitmask() &
2538                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
2539                                    Object[] args = new Object[] {
2540                                                    systemEventModelImpl.getOriginalGroupId(),
2541                                                    systemEventModelImpl.getOriginalClassNameId(),
2542                                                    systemEventModelImpl.getOriginalClassPK()
2543                                            };
2544    
2545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
2546                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
2547                                            args);
2548    
2549                                    args = new Object[] {
2550                                                    systemEventModelImpl.getGroupId(),
2551                                                    systemEventModelImpl.getClassNameId(),
2552                                                    systemEventModelImpl.getClassPK()
2553                                            };
2554    
2555                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
2556                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
2557                                            args);
2558                            }
2559    
2560                            if ((systemEventModelImpl.getColumnBitmask() &
2561                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T.getColumnBitmask()) != 0) {
2562                                    Object[] args = new Object[] {
2563                                                    systemEventModelImpl.getOriginalGroupId(),
2564                                                    systemEventModelImpl.getOriginalClassNameId(),
2565                                                    systemEventModelImpl.getOriginalClassPK(),
2566                                                    systemEventModelImpl.getOriginalType()
2567                                            };
2568    
2569                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_T, args);
2570                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T,
2571                                            args);
2572    
2573                                    args = new Object[] {
2574                                                    systemEventModelImpl.getGroupId(),
2575                                                    systemEventModelImpl.getClassNameId(),
2576                                                    systemEventModelImpl.getClassPK(),
2577                                                    systemEventModelImpl.getType()
2578                                            };
2579    
2580                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_T, args);
2581                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T,
2582                                            args);
2583                            }
2584                    }
2585    
2586                    EntityCacheUtil.putResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2587                            SystemEventImpl.class, systemEvent.getPrimaryKey(), systemEvent);
2588    
2589                    return systemEvent;
2590            }
2591    
2592            protected SystemEvent toUnwrappedModel(SystemEvent systemEvent) {
2593                    if (systemEvent instanceof SystemEventImpl) {
2594                            return systemEvent;
2595                    }
2596    
2597                    SystemEventImpl systemEventImpl = new SystemEventImpl();
2598    
2599                    systemEventImpl.setNew(systemEvent.isNew());
2600                    systemEventImpl.setPrimaryKey(systemEvent.getPrimaryKey());
2601    
2602                    systemEventImpl.setSystemEventId(systemEvent.getSystemEventId());
2603                    systemEventImpl.setGroupId(systemEvent.getGroupId());
2604                    systemEventImpl.setCompanyId(systemEvent.getCompanyId());
2605                    systemEventImpl.setUserId(systemEvent.getUserId());
2606                    systemEventImpl.setUserName(systemEvent.getUserName());
2607                    systemEventImpl.setCreateDate(systemEvent.getCreateDate());
2608                    systemEventImpl.setClassNameId(systemEvent.getClassNameId());
2609                    systemEventImpl.setClassPK(systemEvent.getClassPK());
2610                    systemEventImpl.setClassUuid(systemEvent.getClassUuid());
2611                    systemEventImpl.setReferrerClassNameId(systemEvent.getReferrerClassNameId());
2612                    systemEventImpl.setParentSystemEventId(systemEvent.getParentSystemEventId());
2613                    systemEventImpl.setSystemEventSetKey(systemEvent.getSystemEventSetKey());
2614                    systemEventImpl.setType(systemEvent.getType());
2615                    systemEventImpl.setExtraData(systemEvent.getExtraData());
2616    
2617                    return systemEventImpl;
2618            }
2619    
2620            /**
2621             * Returns the system event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2622             *
2623             * @param primaryKey the primary key of the system event
2624             * @return the system event
2625             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
2626             * @throws SystemException if a system exception occurred
2627             */
2628            @Override
2629            public SystemEvent findByPrimaryKey(Serializable primaryKey)
2630                    throws NoSuchSystemEventException, SystemException {
2631                    SystemEvent systemEvent = fetchByPrimaryKey(primaryKey);
2632    
2633                    if (systemEvent == null) {
2634                            if (_log.isWarnEnabled()) {
2635                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2636                            }
2637    
2638                            throw new NoSuchSystemEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2639                                    primaryKey);
2640                    }
2641    
2642                    return systemEvent;
2643            }
2644    
2645            /**
2646             * Returns the system event with the primary key or throws a {@link com.liferay.portal.NoSuchSystemEventException} if it could not be found.
2647             *
2648             * @param systemEventId the primary key of the system event
2649             * @return the system event
2650             * @throws com.liferay.portal.NoSuchSystemEventException if a system event with the primary key could not be found
2651             * @throws SystemException if a system exception occurred
2652             */
2653            @Override
2654            public SystemEvent findByPrimaryKey(long systemEventId)
2655                    throws NoSuchSystemEventException, SystemException {
2656                    return findByPrimaryKey((Serializable)systemEventId);
2657            }
2658    
2659            /**
2660             * Returns the system event with the primary key or returns <code>null</code> if it could not be found.
2661             *
2662             * @param primaryKey the primary key of the system event
2663             * @return the system event, or <code>null</code> if a system event with the primary key could not be found
2664             * @throws SystemException if a system exception occurred
2665             */
2666            @Override
2667            public SystemEvent fetchByPrimaryKey(Serializable primaryKey)
2668                    throws SystemException {
2669                    SystemEvent systemEvent = (SystemEvent)EntityCacheUtil.getResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2670                                    SystemEventImpl.class, primaryKey);
2671    
2672                    if (systemEvent == _nullSystemEvent) {
2673                            return null;
2674                    }
2675    
2676                    if (systemEvent == null) {
2677                            Session session = null;
2678    
2679                            try {
2680                                    session = openSession();
2681    
2682                                    systemEvent = (SystemEvent)session.get(SystemEventImpl.class,
2683                                                    primaryKey);
2684    
2685                                    if (systemEvent != null) {
2686                                            cacheResult(systemEvent);
2687                                    }
2688                                    else {
2689                                            EntityCacheUtil.putResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2690                                                    SystemEventImpl.class, primaryKey, _nullSystemEvent);
2691                                    }
2692                            }
2693                            catch (Exception e) {
2694                                    EntityCacheUtil.removeResult(SystemEventModelImpl.ENTITY_CACHE_ENABLED,
2695                                            SystemEventImpl.class, primaryKey);
2696    
2697                                    throw processException(e);
2698                            }
2699                            finally {
2700                                    closeSession(session);
2701                            }
2702                    }
2703    
2704                    return systemEvent;
2705            }
2706    
2707            /**
2708             * Returns the system event with the primary key or returns <code>null</code> if it could not be found.
2709             *
2710             * @param systemEventId the primary key of the system event
2711             * @return the system event, or <code>null</code> if a system event with the primary key could not be found
2712             * @throws SystemException if a system exception occurred
2713             */
2714            @Override
2715            public SystemEvent fetchByPrimaryKey(long systemEventId)
2716                    throws SystemException {
2717                    return fetchByPrimaryKey((Serializable)systemEventId);
2718            }
2719    
2720            /**
2721             * Returns all the system events.
2722             *
2723             * @return the system events
2724             * @throws SystemException if a system exception occurred
2725             */
2726            @Override
2727            public List<SystemEvent> findAll() throws SystemException {
2728                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2729            }
2730    
2731            /**
2732             * Returns a range of all the system events.
2733             *
2734             * <p>
2735             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
2736             * </p>
2737             *
2738             * @param start the lower bound of the range of system events
2739             * @param end the upper bound of the range of system events (not inclusive)
2740             * @return the range of system events
2741             * @throws SystemException if a system exception occurred
2742             */
2743            @Override
2744            public List<SystemEvent> findAll(int start, int end)
2745                    throws SystemException {
2746                    return findAll(start, end, null);
2747            }
2748    
2749            /**
2750             * Returns an ordered range of all the system events.
2751             *
2752             * <p>
2753             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.SystemEventModelImpl}. 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.
2754             * </p>
2755             *
2756             * @param start the lower bound of the range of system events
2757             * @param end the upper bound of the range of system events (not inclusive)
2758             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2759             * @return the ordered range of system events
2760             * @throws SystemException if a system exception occurred
2761             */
2762            @Override
2763            public List<SystemEvent> findAll(int start, int end,
2764                    OrderByComparator orderByComparator) throws SystemException {
2765                    boolean pagination = true;
2766                    FinderPath finderPath = null;
2767                    Object[] finderArgs = null;
2768    
2769                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2770                                    (orderByComparator == null)) {
2771                            pagination = false;
2772                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2773                            finderArgs = FINDER_ARGS_EMPTY;
2774                    }
2775                    else {
2776                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2777                            finderArgs = new Object[] { start, end, orderByComparator };
2778                    }
2779    
2780                    List<SystemEvent> list = (List<SystemEvent>)FinderCacheUtil.getResult(finderPath,
2781                                    finderArgs, this);
2782    
2783                    if (list == null) {
2784                            StringBundler query = null;
2785                            String sql = null;
2786    
2787                            if (orderByComparator != null) {
2788                                    query = new StringBundler(2 +
2789                                                    (orderByComparator.getOrderByFields().length * 3));
2790    
2791                                    query.append(_SQL_SELECT_SYSTEMEVENT);
2792    
2793                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2794                                            orderByComparator);
2795    
2796                                    sql = query.toString();
2797                            }
2798                            else {
2799                                    sql = _SQL_SELECT_SYSTEMEVENT;
2800    
2801                                    if (pagination) {
2802                                            sql = sql.concat(SystemEventModelImpl.ORDER_BY_JPQL);
2803                                    }
2804                            }
2805    
2806                            Session session = null;
2807    
2808                            try {
2809                                    session = openSession();
2810    
2811                                    Query q = session.createQuery(sql);
2812    
2813                                    if (!pagination) {
2814                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
2815                                                            start, end, false);
2816    
2817                                            Collections.sort(list);
2818    
2819                                            list = new UnmodifiableList<SystemEvent>(list);
2820                                    }
2821                                    else {
2822                                            list = (List<SystemEvent>)QueryUtil.list(q, getDialect(),
2823                                                            start, end);
2824                                    }
2825    
2826                                    cacheResult(list);
2827    
2828                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2829                            }
2830                            catch (Exception e) {
2831                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2832    
2833                                    throw processException(e);
2834                            }
2835                            finally {
2836                                    closeSession(session);
2837                            }
2838                    }
2839    
2840                    return list;
2841            }
2842    
2843            /**
2844             * Removes all the system events from the database.
2845             *
2846             * @throws SystemException if a system exception occurred
2847             */
2848            @Override
2849            public void removeAll() throws SystemException {
2850                    for (SystemEvent systemEvent : findAll()) {
2851                            remove(systemEvent);
2852                    }
2853            }
2854    
2855            /**
2856             * Returns the number of system events.
2857             *
2858             * @return the number of system events
2859             * @throws SystemException if a system exception occurred
2860             */
2861            @Override
2862            public int countAll() throws SystemException {
2863                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2864                                    FINDER_ARGS_EMPTY, this);
2865    
2866                    if (count == null) {
2867                            Session session = null;
2868    
2869                            try {
2870                                    session = openSession();
2871    
2872                                    Query q = session.createQuery(_SQL_COUNT_SYSTEMEVENT);
2873    
2874                                    count = (Long)q.uniqueResult();
2875    
2876                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2877                                            FINDER_ARGS_EMPTY, count);
2878                            }
2879                            catch (Exception e) {
2880                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2881                                            FINDER_ARGS_EMPTY);
2882    
2883                                    throw processException(e);
2884                            }
2885                            finally {
2886                                    closeSession(session);
2887                            }
2888                    }
2889    
2890                    return count.intValue();
2891            }
2892    
2893            @Override
2894            protected Set<String> getBadColumnNames() {
2895                    return _badColumnNames;
2896            }
2897    
2898            /**
2899             * Initializes the system event persistence.
2900             */
2901            public void afterPropertiesSet() {
2902                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2903                                            com.liferay.portal.util.PropsUtil.get(
2904                                                    "value.object.listener.com.liferay.portal.model.SystemEvent")));
2905    
2906                    if (listenerClassNames.length > 0) {
2907                            try {
2908                                    List<ModelListener<SystemEvent>> listenersList = new ArrayList<ModelListener<SystemEvent>>();
2909    
2910                                    for (String listenerClassName : listenerClassNames) {
2911                                            listenersList.add((ModelListener<SystemEvent>)InstanceFactory.newInstance(
2912                                                            getClassLoader(), listenerClassName));
2913                                    }
2914    
2915                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2916                            }
2917                            catch (Exception e) {
2918                                    _log.error(e);
2919                            }
2920                    }
2921            }
2922    
2923            public void destroy() {
2924                    EntityCacheUtil.removeCache(SystemEventImpl.class.getName());
2925                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2926                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2927                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2928            }
2929    
2930            private static final String _SQL_SELECT_SYSTEMEVENT = "SELECT systemEvent FROM SystemEvent systemEvent";
2931            private static final String _SQL_SELECT_SYSTEMEVENT_WHERE = "SELECT systemEvent FROM SystemEvent systemEvent WHERE ";
2932            private static final String _SQL_COUNT_SYSTEMEVENT = "SELECT COUNT(systemEvent) FROM SystemEvent systemEvent";
2933            private static final String _SQL_COUNT_SYSTEMEVENT_WHERE = "SELECT COUNT(systemEvent) FROM SystemEvent systemEvent WHERE ";
2934            private static final String _ORDER_BY_ENTITY_ALIAS = "systemEvent.";
2935            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SystemEvent exists with the primary key ";
2936            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SystemEvent exists with the key {";
2937            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2938            private static Log _log = LogFactoryUtil.getLog(SystemEventPersistenceImpl.class);
2939            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2940                                    "type"
2941                            });
2942            private static SystemEvent _nullSystemEvent = new SystemEventImpl() {
2943                            @Override
2944                            public Object clone() {
2945                                    return this;
2946                            }
2947    
2948                            @Override
2949                            public CacheModel<SystemEvent> toCacheModel() {
2950                                    return _nullSystemEventCacheModel;
2951                            }
2952                    };
2953    
2954            private static CacheModel<SystemEvent> _nullSystemEventCacheModel = new CacheModel<SystemEvent>() {
2955                            @Override
2956                            public SystemEvent toEntityModel() {
2957                                    return _nullSystemEvent;
2958                            }
2959                    };
2960    }