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