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