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