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