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