001    /**
002     * Copyright (c) 2000-2013 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.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
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.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.documentlibrary.NoSuchSyncEventException;
041    import com.liferay.portlet.documentlibrary.model.DLSyncEvent;
042    import com.liferay.portlet.documentlibrary.model.impl.DLSyncEventImpl;
043    import com.liferay.portlet.documentlibrary.model.impl.DLSyncEventModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the d l sync event service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see DLSyncEventPersistence
061     * @see DLSyncEventUtil
062     * @generated
063     */
064    public class DLSyncEventPersistenceImpl extends BasePersistenceImpl<DLSyncEvent>
065            implements DLSyncEventPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link DLSyncEventUtil} to access the d l sync event persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = DLSyncEventImpl.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(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
077                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, DLSyncEventImpl.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(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
080                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, DLSyncEventImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
083                            DLSyncEventModelImpl.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_MODIFIEDTIME =
086                    new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
087                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, DLSyncEventImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByModifiedTime",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            Integer.class.getName(), Integer.class.getName(),
093                                    OrderByComparator.class.getName()
094                            });
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_MODIFIEDTIME =
096                    new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
097                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByModifiedTime",
099                            new String[] { Long.class.getName() });
100    
101            /**
102             * Returns all the d l sync events where modifiedTime &gt; &#63;.
103             *
104             * @param modifiedTime the modified time
105             * @return the matching d l sync events
106             * @throws SystemException if a system exception occurred
107             */
108            @Override
109            public List<DLSyncEvent> findByModifiedTime(long modifiedTime)
110                    throws SystemException {
111                    return findByModifiedTime(modifiedTime, QueryUtil.ALL_POS,
112                            QueryUtil.ALL_POS, null);
113            }
114    
115            /**
116             * Returns a range of all the d l sync events where modifiedTime &gt; &#63;.
117             *
118             * <p>
119             * 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.portlet.documentlibrary.model.impl.DLSyncEventModelImpl}. 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.
120             * </p>
121             *
122             * @param modifiedTime the modified time
123             * @param start the lower bound of the range of d l sync events
124             * @param end the upper bound of the range of d l sync events (not inclusive)
125             * @return the range of matching d l sync events
126             * @throws SystemException if a system exception occurred
127             */
128            @Override
129            public List<DLSyncEvent> findByModifiedTime(long modifiedTime, int start,
130                    int end) throws SystemException {
131                    return findByModifiedTime(modifiedTime, start, end, null);
132            }
133    
134            /**
135             * Returns an ordered range of all the d l sync events where modifiedTime &gt; &#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.portlet.documentlibrary.model.impl.DLSyncEventModelImpl}. 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 modifiedTime the modified time
142             * @param start the lower bound of the range of d l sync events
143             * @param end the upper bound of the range of d l sync events (not inclusive)
144             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
145             * @return the ordered range of matching d l sync events
146             * @throws SystemException if a system exception occurred
147             */
148            @Override
149            public List<DLSyncEvent> findByModifiedTime(long modifiedTime, int start,
150                    int end, OrderByComparator orderByComparator) throws SystemException {
151                    boolean pagination = true;
152                    FinderPath finderPath = null;
153                    Object[] finderArgs = null;
154    
155                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MODIFIEDTIME;
156                    finderArgs = new Object[] { modifiedTime, start, end, orderByComparator };
157    
158                    List<DLSyncEvent> list = (List<DLSyncEvent>)FinderCacheUtil.getResult(finderPath,
159                                    finderArgs, this);
160    
161                    if ((list != null) && !list.isEmpty()) {
162                            for (DLSyncEvent dlSyncEvent : list) {
163                                    if ((modifiedTime != dlSyncEvent.getModifiedTime())) {
164                                            list = null;
165    
166                                            break;
167                                    }
168                            }
169                    }
170    
171                    if (list == null) {
172                            StringBundler query = null;
173    
174                            if (orderByComparator != null) {
175                                    query = new StringBundler(3 +
176                                                    (orderByComparator.getOrderByFields().length * 3));
177                            }
178                            else {
179                                    query = new StringBundler(3);
180                            }
181    
182                            query.append(_SQL_SELECT_DLSYNCEVENT_WHERE);
183    
184                            query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2);
185    
186                            if (orderByComparator != null) {
187                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
188                                            orderByComparator);
189                            }
190                            else
191                             if (pagination) {
192                                    query.append(DLSyncEventModelImpl.ORDER_BY_JPQL);
193                            }
194    
195                            String sql = query.toString();
196    
197                            Session session = null;
198    
199                            try {
200                                    session = openSession();
201    
202                                    Query q = session.createQuery(sql);
203    
204                                    QueryPos qPos = QueryPos.getInstance(q);
205    
206                                    qPos.add(modifiedTime);
207    
208                                    if (!pagination) {
209                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
210                                                            start, end, false);
211    
212                                            Collections.sort(list);
213    
214                                            list = new UnmodifiableList<DLSyncEvent>(list);
215                                    }
216                                    else {
217                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
218                                                            start, end);
219                                    }
220    
221                                    cacheResult(list);
222    
223                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
224                            }
225                            catch (Exception e) {
226                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
227    
228                                    throw processException(e);
229                            }
230                            finally {
231                                    closeSession(session);
232                            }
233                    }
234    
235                    return list;
236            }
237    
238            /**
239             * Returns the first d l sync event in the ordered set where modifiedTime &gt; &#63;.
240             *
241             * @param modifiedTime the modified time
242             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
243             * @return the first matching d l sync event
244             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a matching d l sync event could not be found
245             * @throws SystemException if a system exception occurred
246             */
247            @Override
248            public DLSyncEvent findByModifiedTime_First(long modifiedTime,
249                    OrderByComparator orderByComparator)
250                    throws NoSuchSyncEventException, SystemException {
251                    DLSyncEvent dlSyncEvent = fetchByModifiedTime_First(modifiedTime,
252                                    orderByComparator);
253    
254                    if (dlSyncEvent != null) {
255                            return dlSyncEvent;
256                    }
257    
258                    StringBundler msg = new StringBundler(4);
259    
260                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
261    
262                    msg.append("modifiedTime=");
263                    msg.append(modifiedTime);
264    
265                    msg.append(StringPool.CLOSE_CURLY_BRACE);
266    
267                    throw new NoSuchSyncEventException(msg.toString());
268            }
269    
270            /**
271             * Returns the first d l sync event in the ordered set where modifiedTime &gt; &#63;.
272             *
273             * @param modifiedTime the modified time
274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
275             * @return the first matching d l sync event, or <code>null</code> if a matching d l sync event could not be found
276             * @throws SystemException if a system exception occurred
277             */
278            @Override
279            public DLSyncEvent fetchByModifiedTime_First(long modifiedTime,
280                    OrderByComparator orderByComparator) throws SystemException {
281                    List<DLSyncEvent> list = findByModifiedTime(modifiedTime, 0, 1,
282                                    orderByComparator);
283    
284                    if (!list.isEmpty()) {
285                            return list.get(0);
286                    }
287    
288                    return null;
289            }
290    
291            /**
292             * Returns the last d l sync event in the ordered set where modifiedTime &gt; &#63;.
293             *
294             * @param modifiedTime the modified time
295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
296             * @return the last matching d l sync event
297             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a matching d l sync event could not be found
298             * @throws SystemException if a system exception occurred
299             */
300            @Override
301            public DLSyncEvent findByModifiedTime_Last(long modifiedTime,
302                    OrderByComparator orderByComparator)
303                    throws NoSuchSyncEventException, SystemException {
304                    DLSyncEvent dlSyncEvent = fetchByModifiedTime_Last(modifiedTime,
305                                    orderByComparator);
306    
307                    if (dlSyncEvent != null) {
308                            return dlSyncEvent;
309                    }
310    
311                    StringBundler msg = new StringBundler(4);
312    
313                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
314    
315                    msg.append("modifiedTime=");
316                    msg.append(modifiedTime);
317    
318                    msg.append(StringPool.CLOSE_CURLY_BRACE);
319    
320                    throw new NoSuchSyncEventException(msg.toString());
321            }
322    
323            /**
324             * Returns the last d l sync event in the ordered set where modifiedTime &gt; &#63;.
325             *
326             * @param modifiedTime the modified time
327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
328             * @return the last matching d l sync event, or <code>null</code> if a matching d l sync event could not be found
329             * @throws SystemException if a system exception occurred
330             */
331            @Override
332            public DLSyncEvent fetchByModifiedTime_Last(long modifiedTime,
333                    OrderByComparator orderByComparator) throws SystemException {
334                    int count = countByModifiedTime(modifiedTime);
335    
336                    if (count == 0) {
337                            return null;
338                    }
339    
340                    List<DLSyncEvent> list = findByModifiedTime(modifiedTime, count - 1,
341                                    count, orderByComparator);
342    
343                    if (!list.isEmpty()) {
344                            return list.get(0);
345                    }
346    
347                    return null;
348            }
349    
350            /**
351             * Returns the d l sync events before and after the current d l sync event in the ordered set where modifiedTime &gt; &#63;.
352             *
353             * @param syncEventId the primary key of the current d l sync event
354             * @param modifiedTime the modified time
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the previous, current, and next d l sync event
357             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
358             * @throws SystemException if a system exception occurred
359             */
360            @Override
361            public DLSyncEvent[] findByModifiedTime_PrevAndNext(long syncEventId,
362                    long modifiedTime, OrderByComparator orderByComparator)
363                    throws NoSuchSyncEventException, SystemException {
364                    DLSyncEvent dlSyncEvent = findByPrimaryKey(syncEventId);
365    
366                    Session session = null;
367    
368                    try {
369                            session = openSession();
370    
371                            DLSyncEvent[] array = new DLSyncEventImpl[3];
372    
373                            array[0] = getByModifiedTime_PrevAndNext(session, dlSyncEvent,
374                                            modifiedTime, orderByComparator, true);
375    
376                            array[1] = dlSyncEvent;
377    
378                            array[2] = getByModifiedTime_PrevAndNext(session, dlSyncEvent,
379                                            modifiedTime, 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 DLSyncEvent getByModifiedTime_PrevAndNext(Session session,
392                    DLSyncEvent dlSyncEvent, long modifiedTime,
393                    OrderByComparator 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_DLSYNCEVENT_WHERE);
405    
406                    query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_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(DLSyncEventModelImpl.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(modifiedTime);
477    
478                    if (orderByComparator != null) {
479                            Object[] values = orderByComparator.getOrderByConditionValues(dlSyncEvent);
480    
481                            for (Object value : values) {
482                                    qPos.add(value);
483                            }
484                    }
485    
486                    List<DLSyncEvent> 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 d l sync events where modifiedTime &gt; &#63; from the database.
498             *
499             * @param modifiedTime the modified time
500             * @throws SystemException if a system exception occurred
501             */
502            @Override
503            public void removeByModifiedTime(long modifiedTime)
504                    throws SystemException {
505                    for (DLSyncEvent dlSyncEvent : findByModifiedTime(modifiedTime,
506                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
507                            remove(dlSyncEvent);
508                    }
509            }
510    
511            /**
512             * Returns the number of d l sync events where modifiedTime &gt; &#63;.
513             *
514             * @param modifiedTime the modified time
515             * @return the number of matching d l sync events
516             * @throws SystemException if a system exception occurred
517             */
518            @Override
519            public int countByModifiedTime(long modifiedTime) throws SystemException {
520                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_MODIFIEDTIME;
521    
522                    Object[] finderArgs = new Object[] { modifiedTime };
523    
524                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
525                                    this);
526    
527                    if (count == null) {
528                            StringBundler query = new StringBundler(2);
529    
530                            query.append(_SQL_COUNT_DLSYNCEVENT_WHERE);
531    
532                            query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2);
533    
534                            String sql = query.toString();
535    
536                            Session session = null;
537    
538                            try {
539                                    session = openSession();
540    
541                                    Query q = session.createQuery(sql);
542    
543                                    QueryPos qPos = QueryPos.getInstance(q);
544    
545                                    qPos.add(modifiedTime);
546    
547                                    count = (Long)q.uniqueResult();
548    
549                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
550                            }
551                            catch (Exception e) {
552                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
553    
554                                    throw processException(e);
555                            }
556                            finally {
557                                    closeSession(session);
558                            }
559                    }
560    
561                    return count.intValue();
562            }
563    
564            private static final String _FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2 = "dlSyncEvent.modifiedTime > ?";
565            public static final FinderPath FINDER_PATH_FETCH_BY_TYPEPK = new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
566                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, DLSyncEventImpl.class,
567                            FINDER_CLASS_NAME_ENTITY, "fetchByTypePK",
568                            new String[] { Long.class.getName() },
569                            DLSyncEventModelImpl.TYPEPK_COLUMN_BITMASK);
570            public static final FinderPath FINDER_PATH_COUNT_BY_TYPEPK = new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
571                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
572                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTypePK",
573                            new String[] { Long.class.getName() });
574    
575            /**
576             * Returns the d l sync event where typePK = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchSyncEventException} if it could not be found.
577             *
578             * @param typePK the type p k
579             * @return the matching d l sync event
580             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a matching d l sync event could not be found
581             * @throws SystemException if a system exception occurred
582             */
583            @Override
584            public DLSyncEvent findByTypePK(long typePK)
585                    throws NoSuchSyncEventException, SystemException {
586                    DLSyncEvent dlSyncEvent = fetchByTypePK(typePK);
587    
588                    if (dlSyncEvent == null) {
589                            StringBundler msg = new StringBundler(4);
590    
591                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
592    
593                            msg.append("typePK=");
594                            msg.append(typePK);
595    
596                            msg.append(StringPool.CLOSE_CURLY_BRACE);
597    
598                            if (_log.isWarnEnabled()) {
599                                    _log.warn(msg.toString());
600                            }
601    
602                            throw new NoSuchSyncEventException(msg.toString());
603                    }
604    
605                    return dlSyncEvent;
606            }
607    
608            /**
609             * Returns the d l sync event where typePK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
610             *
611             * @param typePK the type p k
612             * @return the matching d l sync event, or <code>null</code> if a matching d l sync event could not be found
613             * @throws SystemException if a system exception occurred
614             */
615            @Override
616            public DLSyncEvent fetchByTypePK(long typePK) throws SystemException {
617                    return fetchByTypePK(typePK, true);
618            }
619    
620            /**
621             * Returns the d l sync event where typePK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
622             *
623             * @param typePK the type p k
624             * @param retrieveFromCache whether to use the finder cache
625             * @return the matching d l sync event, or <code>null</code> if a matching d l sync event could not be found
626             * @throws SystemException if a system exception occurred
627             */
628            @Override
629            public DLSyncEvent fetchByTypePK(long typePK, boolean retrieveFromCache)
630                    throws SystemException {
631                    Object[] finderArgs = new Object[] { typePK };
632    
633                    Object result = null;
634    
635                    if (retrieveFromCache) {
636                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_TYPEPK,
637                                            finderArgs, this);
638                    }
639    
640                    if (result instanceof DLSyncEvent) {
641                            DLSyncEvent dlSyncEvent = (DLSyncEvent)result;
642    
643                            if ((typePK != dlSyncEvent.getTypePK())) {
644                                    result = null;
645                            }
646                    }
647    
648                    if (result == null) {
649                            StringBundler query = new StringBundler(3);
650    
651                            query.append(_SQL_SELECT_DLSYNCEVENT_WHERE);
652    
653                            query.append(_FINDER_COLUMN_TYPEPK_TYPEPK_2);
654    
655                            String sql = query.toString();
656    
657                            Session session = null;
658    
659                            try {
660                                    session = openSession();
661    
662                                    Query q = session.createQuery(sql);
663    
664                                    QueryPos qPos = QueryPos.getInstance(q);
665    
666                                    qPos.add(typePK);
667    
668                                    List<DLSyncEvent> list = q.list();
669    
670                                    if (list.isEmpty()) {
671                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
672                                                    finderArgs, list);
673                                    }
674                                    else {
675                                            DLSyncEvent dlSyncEvent = list.get(0);
676    
677                                            result = dlSyncEvent;
678    
679                                            cacheResult(dlSyncEvent);
680    
681                                            if ((dlSyncEvent.getTypePK() != typePK)) {
682                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
683                                                            finderArgs, dlSyncEvent);
684                                            }
685                                    }
686                            }
687                            catch (Exception e) {
688                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TYPEPK,
689                                            finderArgs);
690    
691                                    throw processException(e);
692                            }
693                            finally {
694                                    closeSession(session);
695                            }
696                    }
697    
698                    if (result instanceof List<?>) {
699                            return null;
700                    }
701                    else {
702                            return (DLSyncEvent)result;
703                    }
704            }
705    
706            /**
707             * Removes the d l sync event where typePK = &#63; from the database.
708             *
709             * @param typePK the type p k
710             * @return the d l sync event that was removed
711             * @throws SystemException if a system exception occurred
712             */
713            @Override
714            public DLSyncEvent removeByTypePK(long typePK)
715                    throws NoSuchSyncEventException, SystemException {
716                    DLSyncEvent dlSyncEvent = findByTypePK(typePK);
717    
718                    return remove(dlSyncEvent);
719            }
720    
721            /**
722             * Returns the number of d l sync events where typePK = &#63;.
723             *
724             * @param typePK the type p k
725             * @return the number of matching d l sync events
726             * @throws SystemException if a system exception occurred
727             */
728            @Override
729            public int countByTypePK(long typePK) throws SystemException {
730                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPEPK;
731    
732                    Object[] finderArgs = new Object[] { typePK };
733    
734                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
735                                    this);
736    
737                    if (count == null) {
738                            StringBundler query = new StringBundler(2);
739    
740                            query.append(_SQL_COUNT_DLSYNCEVENT_WHERE);
741    
742                            query.append(_FINDER_COLUMN_TYPEPK_TYPEPK_2);
743    
744                            String sql = query.toString();
745    
746                            Session session = null;
747    
748                            try {
749                                    session = openSession();
750    
751                                    Query q = session.createQuery(sql);
752    
753                                    QueryPos qPos = QueryPos.getInstance(q);
754    
755                                    qPos.add(typePK);
756    
757                                    count = (Long)q.uniqueResult();
758    
759                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
760                            }
761                            catch (Exception e) {
762                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
763    
764                                    throw processException(e);
765                            }
766                            finally {
767                                    closeSession(session);
768                            }
769                    }
770    
771                    return count.intValue();
772            }
773    
774            private static final String _FINDER_COLUMN_TYPEPK_TYPEPK_2 = "dlSyncEvent.typePK = ?";
775    
776            /**
777             * Caches the d l sync event in the entity cache if it is enabled.
778             *
779             * @param dlSyncEvent the d l sync event
780             */
781            @Override
782            public void cacheResult(DLSyncEvent dlSyncEvent) {
783                    EntityCacheUtil.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
784                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey(), dlSyncEvent);
785    
786                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
787                            new Object[] { dlSyncEvent.getTypePK() }, dlSyncEvent);
788    
789                    dlSyncEvent.resetOriginalValues();
790            }
791    
792            /**
793             * Caches the d l sync events in the entity cache if it is enabled.
794             *
795             * @param dlSyncEvents the d l sync events
796             */
797            @Override
798            public void cacheResult(List<DLSyncEvent> dlSyncEvents) {
799                    for (DLSyncEvent dlSyncEvent : dlSyncEvents) {
800                            if (EntityCacheUtil.getResult(
801                                                    DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
802                                                    DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey()) == null) {
803                                    cacheResult(dlSyncEvent);
804                            }
805                            else {
806                                    dlSyncEvent.resetOriginalValues();
807                            }
808                    }
809            }
810    
811            /**
812             * Clears the cache for all d l sync events.
813             *
814             * <p>
815             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
816             * </p>
817             */
818            @Override
819            public void clearCache() {
820                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
821                            CacheRegistryUtil.clear(DLSyncEventImpl.class.getName());
822                    }
823    
824                    EntityCacheUtil.clearCache(DLSyncEventImpl.class.getName());
825    
826                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
827                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
828                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
829            }
830    
831            /**
832             * Clears the cache for the d l sync event.
833             *
834             * <p>
835             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
836             * </p>
837             */
838            @Override
839            public void clearCache(DLSyncEvent dlSyncEvent) {
840                    EntityCacheUtil.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
841                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey());
842    
843                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
844                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
845    
846                    clearUniqueFindersCache(dlSyncEvent);
847            }
848    
849            @Override
850            public void clearCache(List<DLSyncEvent> dlSyncEvents) {
851                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
852                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
853    
854                    for (DLSyncEvent dlSyncEvent : dlSyncEvents) {
855                            EntityCacheUtil.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
856                                    DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey());
857    
858                            clearUniqueFindersCache(dlSyncEvent);
859                    }
860            }
861    
862            protected void cacheUniqueFindersCache(DLSyncEvent dlSyncEvent) {
863                    if (dlSyncEvent.isNew()) {
864                            Object[] args = new Object[] { dlSyncEvent.getTypePK() };
865    
866                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPEPK, args,
867                                    Long.valueOf(1));
868                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK, args,
869                                    dlSyncEvent);
870                    }
871                    else {
872                            DLSyncEventModelImpl dlSyncEventModelImpl = (DLSyncEventModelImpl)dlSyncEvent;
873    
874                            if ((dlSyncEventModelImpl.getColumnBitmask() &
875                                            FINDER_PATH_FETCH_BY_TYPEPK.getColumnBitmask()) != 0) {
876                                    Object[] args = new Object[] { dlSyncEvent.getTypePK() };
877    
878                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPEPK, args,
879                                            Long.valueOf(1));
880                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK, args,
881                                            dlSyncEvent);
882                            }
883                    }
884            }
885    
886            protected void clearUniqueFindersCache(DLSyncEvent dlSyncEvent) {
887                    DLSyncEventModelImpl dlSyncEventModelImpl = (DLSyncEventModelImpl)dlSyncEvent;
888    
889                    Object[] args = new Object[] { dlSyncEvent.getTypePK() };
890    
891                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPEPK, args);
892                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, args);
893    
894                    if ((dlSyncEventModelImpl.getColumnBitmask() &
895                                    FINDER_PATH_FETCH_BY_TYPEPK.getColumnBitmask()) != 0) {
896                            args = new Object[] { dlSyncEventModelImpl.getOriginalTypePK() };
897    
898                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPEPK, args);
899                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, args);
900                    }
901            }
902    
903            /**
904             * Creates a new d l sync event with the primary key. Does not add the d l sync event to the database.
905             *
906             * @param syncEventId the primary key for the new d l sync event
907             * @return the new d l sync event
908             */
909            @Override
910            public DLSyncEvent create(long syncEventId) {
911                    DLSyncEvent dlSyncEvent = new DLSyncEventImpl();
912    
913                    dlSyncEvent.setNew(true);
914                    dlSyncEvent.setPrimaryKey(syncEventId);
915    
916                    return dlSyncEvent;
917            }
918    
919            /**
920             * Removes the d l sync event with the primary key from the database. Also notifies the appropriate model listeners.
921             *
922             * @param syncEventId the primary key of the d l sync event
923             * @return the d l sync event that was removed
924             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
925             * @throws SystemException if a system exception occurred
926             */
927            @Override
928            public DLSyncEvent remove(long syncEventId)
929                    throws NoSuchSyncEventException, SystemException {
930                    return remove((Serializable)syncEventId);
931            }
932    
933            /**
934             * Removes the d l sync event with the primary key from the database. Also notifies the appropriate model listeners.
935             *
936             * @param primaryKey the primary key of the d l sync event
937             * @return the d l sync event that was removed
938             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
939             * @throws SystemException if a system exception occurred
940             */
941            @Override
942            public DLSyncEvent remove(Serializable primaryKey)
943                    throws NoSuchSyncEventException, SystemException {
944                    Session session = null;
945    
946                    try {
947                            session = openSession();
948    
949                            DLSyncEvent dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
950                                            primaryKey);
951    
952                            if (dlSyncEvent == null) {
953                                    if (_log.isWarnEnabled()) {
954                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
955                                    }
956    
957                                    throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
958                                            primaryKey);
959                            }
960    
961                            return remove(dlSyncEvent);
962                    }
963                    catch (NoSuchSyncEventException nsee) {
964                            throw nsee;
965                    }
966                    catch (Exception e) {
967                            throw processException(e);
968                    }
969                    finally {
970                            closeSession(session);
971                    }
972            }
973    
974            @Override
975            protected DLSyncEvent removeImpl(DLSyncEvent dlSyncEvent)
976                    throws SystemException {
977                    dlSyncEvent = toUnwrappedModel(dlSyncEvent);
978    
979                    Session session = null;
980    
981                    try {
982                            session = openSession();
983    
984                            if (!session.contains(dlSyncEvent)) {
985                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
986                                                    dlSyncEvent.getPrimaryKeyObj());
987                            }
988    
989                            if (dlSyncEvent != null) {
990                                    session.delete(dlSyncEvent);
991                            }
992                    }
993                    catch (Exception e) {
994                            throw processException(e);
995                    }
996                    finally {
997                            closeSession(session);
998                    }
999    
1000                    if (dlSyncEvent != null) {
1001                            clearCache(dlSyncEvent);
1002                    }
1003    
1004                    return dlSyncEvent;
1005            }
1006    
1007            @Override
1008            public DLSyncEvent updateImpl(
1009                    com.liferay.portlet.documentlibrary.model.DLSyncEvent dlSyncEvent)
1010                    throws SystemException {
1011                    dlSyncEvent = toUnwrappedModel(dlSyncEvent);
1012    
1013                    boolean isNew = dlSyncEvent.isNew();
1014    
1015                    Session session = null;
1016    
1017                    try {
1018                            session = openSession();
1019    
1020                            if (dlSyncEvent.isNew()) {
1021                                    session.save(dlSyncEvent);
1022    
1023                                    dlSyncEvent.setNew(false);
1024                            }
1025                            else {
1026                                    session.merge(dlSyncEvent);
1027                            }
1028                    }
1029                    catch (Exception e) {
1030                            throw processException(e);
1031                    }
1032                    finally {
1033                            closeSession(session);
1034                    }
1035    
1036                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1037    
1038                    if (isNew || !DLSyncEventModelImpl.COLUMN_BITMASK_ENABLED) {
1039                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1040                    }
1041    
1042                    EntityCacheUtil.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1043                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey(), dlSyncEvent);
1044    
1045                    clearUniqueFindersCache(dlSyncEvent);
1046                    cacheUniqueFindersCache(dlSyncEvent);
1047    
1048                    return dlSyncEvent;
1049            }
1050    
1051            protected DLSyncEvent toUnwrappedModel(DLSyncEvent dlSyncEvent) {
1052                    if (dlSyncEvent instanceof DLSyncEventImpl) {
1053                            return dlSyncEvent;
1054                    }
1055    
1056                    DLSyncEventImpl dlSyncEventImpl = new DLSyncEventImpl();
1057    
1058                    dlSyncEventImpl.setNew(dlSyncEvent.isNew());
1059                    dlSyncEventImpl.setPrimaryKey(dlSyncEvent.getPrimaryKey());
1060    
1061                    dlSyncEventImpl.setSyncEventId(dlSyncEvent.getSyncEventId());
1062                    dlSyncEventImpl.setModifiedTime(dlSyncEvent.getModifiedTime());
1063                    dlSyncEventImpl.setEvent(dlSyncEvent.getEvent());
1064                    dlSyncEventImpl.setType(dlSyncEvent.getType());
1065                    dlSyncEventImpl.setTypePK(dlSyncEvent.getTypePK());
1066    
1067                    return dlSyncEventImpl;
1068            }
1069    
1070            /**
1071             * Returns the d l sync event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1072             *
1073             * @param primaryKey the primary key of the d l sync event
1074             * @return the d l sync event
1075             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
1076             * @throws SystemException if a system exception occurred
1077             */
1078            @Override
1079            public DLSyncEvent findByPrimaryKey(Serializable primaryKey)
1080                    throws NoSuchSyncEventException, SystemException {
1081                    DLSyncEvent dlSyncEvent = fetchByPrimaryKey(primaryKey);
1082    
1083                    if (dlSyncEvent == null) {
1084                            if (_log.isWarnEnabled()) {
1085                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1086                            }
1087    
1088                            throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1089                                    primaryKey);
1090                    }
1091    
1092                    return dlSyncEvent;
1093            }
1094    
1095            /**
1096             * Returns the d l sync event with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchSyncEventException} if it could not be found.
1097             *
1098             * @param syncEventId the primary key of the d l sync event
1099             * @return the d l sync event
1100             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
1101             * @throws SystemException if a system exception occurred
1102             */
1103            @Override
1104            public DLSyncEvent findByPrimaryKey(long syncEventId)
1105                    throws NoSuchSyncEventException, SystemException {
1106                    return findByPrimaryKey((Serializable)syncEventId);
1107            }
1108    
1109            /**
1110             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1111             *
1112             * @param primaryKey the primary key of the d l sync event
1113             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1114             * @throws SystemException if a system exception occurred
1115             */
1116            @Override
1117            public DLSyncEvent fetchByPrimaryKey(Serializable primaryKey)
1118                    throws SystemException {
1119                    DLSyncEvent dlSyncEvent = (DLSyncEvent)EntityCacheUtil.getResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1120                                    DLSyncEventImpl.class, primaryKey);
1121    
1122                    if (dlSyncEvent == _nullDLSyncEvent) {
1123                            return null;
1124                    }
1125    
1126                    if (dlSyncEvent == null) {
1127                            Session session = null;
1128    
1129                            try {
1130                                    session = openSession();
1131    
1132                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
1133                                                    primaryKey);
1134    
1135                                    if (dlSyncEvent != null) {
1136                                            cacheResult(dlSyncEvent);
1137                                    }
1138                                    else {
1139                                            EntityCacheUtil.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1140                                                    DLSyncEventImpl.class, primaryKey, _nullDLSyncEvent);
1141                                    }
1142                            }
1143                            catch (Exception e) {
1144                                    EntityCacheUtil.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1145                                            DLSyncEventImpl.class, primaryKey);
1146    
1147                                    throw processException(e);
1148                            }
1149                            finally {
1150                                    closeSession(session);
1151                            }
1152                    }
1153    
1154                    return dlSyncEvent;
1155            }
1156    
1157            /**
1158             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1159             *
1160             * @param syncEventId the primary key of the d l sync event
1161             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1162             * @throws SystemException if a system exception occurred
1163             */
1164            @Override
1165            public DLSyncEvent fetchByPrimaryKey(long syncEventId)
1166                    throws SystemException {
1167                    return fetchByPrimaryKey((Serializable)syncEventId);
1168            }
1169    
1170            /**
1171             * Returns all the d l sync events.
1172             *
1173             * @return the d l sync events
1174             * @throws SystemException if a system exception occurred
1175             */
1176            @Override
1177            public List<DLSyncEvent> findAll() throws SystemException {
1178                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1179            }
1180    
1181            /**
1182             * Returns a range of all the d l sync events.
1183             *
1184             * <p>
1185             * 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.portlet.documentlibrary.model.impl.DLSyncEventModelImpl}. 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.
1186             * </p>
1187             *
1188             * @param start the lower bound of the range of d l sync events
1189             * @param end the upper bound of the range of d l sync events (not inclusive)
1190             * @return the range of d l sync events
1191             * @throws SystemException if a system exception occurred
1192             */
1193            @Override
1194            public List<DLSyncEvent> findAll(int start, int end)
1195                    throws SystemException {
1196                    return findAll(start, end, null);
1197            }
1198    
1199            /**
1200             * Returns an ordered range of all the d l sync events.
1201             *
1202             * <p>
1203             * 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.portlet.documentlibrary.model.impl.DLSyncEventModelImpl}. 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.
1204             * </p>
1205             *
1206             * @param start the lower bound of the range of d l sync events
1207             * @param end the upper bound of the range of d l sync events (not inclusive)
1208             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1209             * @return the ordered range of d l sync events
1210             * @throws SystemException if a system exception occurred
1211             */
1212            @Override
1213            public List<DLSyncEvent> findAll(int start, int end,
1214                    OrderByComparator orderByComparator) throws SystemException {
1215                    boolean pagination = true;
1216                    FinderPath finderPath = null;
1217                    Object[] finderArgs = null;
1218    
1219                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1220                                    (orderByComparator == null)) {
1221                            pagination = false;
1222                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1223                            finderArgs = FINDER_ARGS_EMPTY;
1224                    }
1225                    else {
1226                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1227                            finderArgs = new Object[] { start, end, orderByComparator };
1228                    }
1229    
1230                    List<DLSyncEvent> list = (List<DLSyncEvent>)FinderCacheUtil.getResult(finderPath,
1231                                    finderArgs, this);
1232    
1233                    if (list == null) {
1234                            StringBundler query = null;
1235                            String sql = null;
1236    
1237                            if (orderByComparator != null) {
1238                                    query = new StringBundler(2 +
1239                                                    (orderByComparator.getOrderByFields().length * 3));
1240    
1241                                    query.append(_SQL_SELECT_DLSYNCEVENT);
1242    
1243                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1244                                            orderByComparator);
1245    
1246                                    sql = query.toString();
1247                            }
1248                            else {
1249                                    sql = _SQL_SELECT_DLSYNCEVENT;
1250    
1251                                    if (pagination) {
1252                                            sql = sql.concat(DLSyncEventModelImpl.ORDER_BY_JPQL);
1253                                    }
1254                            }
1255    
1256                            Session session = null;
1257    
1258                            try {
1259                                    session = openSession();
1260    
1261                                    Query q = session.createQuery(sql);
1262    
1263                                    if (!pagination) {
1264                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1265                                                            start, end, false);
1266    
1267                                            Collections.sort(list);
1268    
1269                                            list = new UnmodifiableList<DLSyncEvent>(list);
1270                                    }
1271                                    else {
1272                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1273                                                            start, end);
1274                                    }
1275    
1276                                    cacheResult(list);
1277    
1278                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1279                            }
1280                            catch (Exception e) {
1281                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1282    
1283                                    throw processException(e);
1284                            }
1285                            finally {
1286                                    closeSession(session);
1287                            }
1288                    }
1289    
1290                    return list;
1291            }
1292    
1293            /**
1294             * Removes all the d l sync events from the database.
1295             *
1296             * @throws SystemException if a system exception occurred
1297             */
1298            @Override
1299            public void removeAll() throws SystemException {
1300                    for (DLSyncEvent dlSyncEvent : findAll()) {
1301                            remove(dlSyncEvent);
1302                    }
1303            }
1304    
1305            /**
1306             * Returns the number of d l sync events.
1307             *
1308             * @return the number of d l sync events
1309             * @throws SystemException if a system exception occurred
1310             */
1311            @Override
1312            public int countAll() throws SystemException {
1313                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1314                                    FINDER_ARGS_EMPTY, this);
1315    
1316                    if (count == null) {
1317                            Session session = null;
1318    
1319                            try {
1320                                    session = openSession();
1321    
1322                                    Query q = session.createQuery(_SQL_COUNT_DLSYNCEVENT);
1323    
1324                                    count = (Long)q.uniqueResult();
1325    
1326                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1327                                            FINDER_ARGS_EMPTY, count);
1328                            }
1329                            catch (Exception e) {
1330                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1331                                            FINDER_ARGS_EMPTY);
1332    
1333                                    throw processException(e);
1334                            }
1335                            finally {
1336                                    closeSession(session);
1337                            }
1338                    }
1339    
1340                    return count.intValue();
1341            }
1342    
1343            @Override
1344            protected Set<String> getBadColumnNames() {
1345                    return _badColumnNames;
1346            }
1347    
1348            /**
1349             * Initializes the d l sync event persistence.
1350             */
1351            public void afterPropertiesSet() {
1352                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1353                                            com.liferay.portal.util.PropsUtil.get(
1354                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLSyncEvent")));
1355    
1356                    if (listenerClassNames.length > 0) {
1357                            try {
1358                                    List<ModelListener<DLSyncEvent>> listenersList = new ArrayList<ModelListener<DLSyncEvent>>();
1359    
1360                                    for (String listenerClassName : listenerClassNames) {
1361                                            listenersList.add((ModelListener<DLSyncEvent>)InstanceFactory.newInstance(
1362                                                            getClassLoader(), listenerClassName));
1363                                    }
1364    
1365                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1366                            }
1367                            catch (Exception e) {
1368                                    _log.error(e);
1369                            }
1370                    }
1371            }
1372    
1373            public void destroy() {
1374                    EntityCacheUtil.removeCache(DLSyncEventImpl.class.getName());
1375                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1376                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1377                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1378            }
1379    
1380            private static final String _SQL_SELECT_DLSYNCEVENT = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent";
1381            private static final String _SQL_SELECT_DLSYNCEVENT_WHERE = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent WHERE ";
1382            private static final String _SQL_COUNT_DLSYNCEVENT = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent";
1383            private static final String _SQL_COUNT_DLSYNCEVENT_WHERE = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent WHERE ";
1384            private static final String _ORDER_BY_ENTITY_ALIAS = "dlSyncEvent.";
1385            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSyncEvent exists with the primary key ";
1386            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSyncEvent exists with the key {";
1387            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1388            private static Log _log = LogFactoryUtil.getLog(DLSyncEventPersistenceImpl.class);
1389            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1390                                    "type"
1391                            });
1392            private static DLSyncEvent _nullDLSyncEvent = new DLSyncEventImpl() {
1393                            @Override
1394                            public Object clone() {
1395                                    return this;
1396                            }
1397    
1398                            @Override
1399                            public CacheModel<DLSyncEvent> toCacheModel() {
1400                                    return _nullDLSyncEventCacheModel;
1401                            }
1402                    };
1403    
1404            private static CacheModel<DLSyncEvent> _nullDLSyncEventCacheModel = new CacheModel<DLSyncEvent>() {
1405                            @Override
1406                            public DLSyncEvent toEntityModel() {
1407                                    return _nullDLSyncEvent;
1408                            }
1409                    };
1410    }