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