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