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            public DLSyncEventPersistenceImpl() {
777                    setModelClass(DLSyncEvent.class);
778            }
779    
780            /**
781             * Caches the d l sync event in the entity cache if it is enabled.
782             *
783             * @param dlSyncEvent the d l sync event
784             */
785            @Override
786            public void cacheResult(DLSyncEvent dlSyncEvent) {
787                    EntityCacheUtil.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
788                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey(), dlSyncEvent);
789    
790                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
791                            new Object[] { dlSyncEvent.getTypePK() }, dlSyncEvent);
792    
793                    dlSyncEvent.resetOriginalValues();
794            }
795    
796            /**
797             * Caches the d l sync events in the entity cache if it is enabled.
798             *
799             * @param dlSyncEvents the d l sync events
800             */
801            @Override
802            public void cacheResult(List<DLSyncEvent> dlSyncEvents) {
803                    for (DLSyncEvent dlSyncEvent : dlSyncEvents) {
804                            if (EntityCacheUtil.getResult(
805                                                    DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
806                                                    DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey()) == null) {
807                                    cacheResult(dlSyncEvent);
808                            }
809                            else {
810                                    dlSyncEvent.resetOriginalValues();
811                            }
812                    }
813            }
814    
815            /**
816             * Clears the cache for all d l sync events.
817             *
818             * <p>
819             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
820             * </p>
821             */
822            @Override
823            public void clearCache() {
824                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
825                            CacheRegistryUtil.clear(DLSyncEventImpl.class.getName());
826                    }
827    
828                    EntityCacheUtil.clearCache(DLSyncEventImpl.class.getName());
829    
830                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
831                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
832                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
833            }
834    
835            /**
836             * Clears the cache for the d l sync event.
837             *
838             * <p>
839             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
840             * </p>
841             */
842            @Override
843            public void clearCache(DLSyncEvent dlSyncEvent) {
844                    EntityCacheUtil.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
845                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey());
846    
847                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
848                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
849    
850                    clearUniqueFindersCache(dlSyncEvent);
851            }
852    
853            @Override
854            public void clearCache(List<DLSyncEvent> dlSyncEvents) {
855                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
856                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
857    
858                    for (DLSyncEvent dlSyncEvent : dlSyncEvents) {
859                            EntityCacheUtil.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
860                                    DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey());
861    
862                            clearUniqueFindersCache(dlSyncEvent);
863                    }
864            }
865    
866            protected void cacheUniqueFindersCache(DLSyncEvent dlSyncEvent) {
867                    if (dlSyncEvent.isNew()) {
868                            Object[] args = new Object[] { dlSyncEvent.getTypePK() };
869    
870                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPEPK, args,
871                                    Long.valueOf(1));
872                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK, args,
873                                    dlSyncEvent);
874                    }
875                    else {
876                            DLSyncEventModelImpl dlSyncEventModelImpl = (DLSyncEventModelImpl)dlSyncEvent;
877    
878                            if ((dlSyncEventModelImpl.getColumnBitmask() &
879                                            FINDER_PATH_FETCH_BY_TYPEPK.getColumnBitmask()) != 0) {
880                                    Object[] args = new Object[] { dlSyncEvent.getTypePK() };
881    
882                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPEPK, args,
883                                            Long.valueOf(1));
884                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TYPEPK, args,
885                                            dlSyncEvent);
886                            }
887                    }
888            }
889    
890            protected void clearUniqueFindersCache(DLSyncEvent dlSyncEvent) {
891                    DLSyncEventModelImpl dlSyncEventModelImpl = (DLSyncEventModelImpl)dlSyncEvent;
892    
893                    Object[] args = new Object[] { dlSyncEvent.getTypePK() };
894    
895                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPEPK, args);
896                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, args);
897    
898                    if ((dlSyncEventModelImpl.getColumnBitmask() &
899                                    FINDER_PATH_FETCH_BY_TYPEPK.getColumnBitmask()) != 0) {
900                            args = new Object[] { dlSyncEventModelImpl.getOriginalTypePK() };
901    
902                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPEPK, args);
903                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, args);
904                    }
905            }
906    
907            /**
908             * Creates a new d l sync event with the primary key. Does not add the d l sync event to the database.
909             *
910             * @param syncEventId the primary key for the new d l sync event
911             * @return the new d l sync event
912             */
913            @Override
914            public DLSyncEvent create(long syncEventId) {
915                    DLSyncEvent dlSyncEvent = new DLSyncEventImpl();
916    
917                    dlSyncEvent.setNew(true);
918                    dlSyncEvent.setPrimaryKey(syncEventId);
919    
920                    return dlSyncEvent;
921            }
922    
923            /**
924             * Removes the d l sync event with the primary key from the database. Also notifies the appropriate model listeners.
925             *
926             * @param syncEventId the primary key of the d l sync event
927             * @return the d l sync event that was removed
928             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
929             * @throws SystemException if a system exception occurred
930             */
931            @Override
932            public DLSyncEvent remove(long syncEventId)
933                    throws NoSuchSyncEventException, SystemException {
934                    return remove((Serializable)syncEventId);
935            }
936    
937            /**
938             * Removes the d l sync event with the primary key from the database. Also notifies the appropriate model listeners.
939             *
940             * @param primaryKey the primary key of the d l sync event
941             * @return the d l sync event that was removed
942             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
943             * @throws SystemException if a system exception occurred
944             */
945            @Override
946            public DLSyncEvent remove(Serializable primaryKey)
947                    throws NoSuchSyncEventException, SystemException {
948                    Session session = null;
949    
950                    try {
951                            session = openSession();
952    
953                            DLSyncEvent dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
954                                            primaryKey);
955    
956                            if (dlSyncEvent == null) {
957                                    if (_log.isWarnEnabled()) {
958                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
959                                    }
960    
961                                    throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
962                                            primaryKey);
963                            }
964    
965                            return remove(dlSyncEvent);
966                    }
967                    catch (NoSuchSyncEventException nsee) {
968                            throw nsee;
969                    }
970                    catch (Exception e) {
971                            throw processException(e);
972                    }
973                    finally {
974                            closeSession(session);
975                    }
976            }
977    
978            @Override
979            protected DLSyncEvent removeImpl(DLSyncEvent dlSyncEvent)
980                    throws SystemException {
981                    dlSyncEvent = toUnwrappedModel(dlSyncEvent);
982    
983                    Session session = null;
984    
985                    try {
986                            session = openSession();
987    
988                            if (!session.contains(dlSyncEvent)) {
989                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
990                                                    dlSyncEvent.getPrimaryKeyObj());
991                            }
992    
993                            if (dlSyncEvent != null) {
994                                    session.delete(dlSyncEvent);
995                            }
996                    }
997                    catch (Exception e) {
998                            throw processException(e);
999                    }
1000                    finally {
1001                            closeSession(session);
1002                    }
1003    
1004                    if (dlSyncEvent != null) {
1005                            clearCache(dlSyncEvent);
1006                    }
1007    
1008                    return dlSyncEvent;
1009            }
1010    
1011            @Override
1012            public DLSyncEvent updateImpl(
1013                    com.liferay.portlet.documentlibrary.model.DLSyncEvent dlSyncEvent)
1014                    throws SystemException {
1015                    dlSyncEvent = toUnwrappedModel(dlSyncEvent);
1016    
1017                    boolean isNew = dlSyncEvent.isNew();
1018    
1019                    Session session = null;
1020    
1021                    try {
1022                            session = openSession();
1023    
1024                            if (dlSyncEvent.isNew()) {
1025                                    session.save(dlSyncEvent);
1026    
1027                                    dlSyncEvent.setNew(false);
1028                            }
1029                            else {
1030                                    session.merge(dlSyncEvent);
1031                            }
1032                    }
1033                    catch (Exception e) {
1034                            throw processException(e);
1035                    }
1036                    finally {
1037                            closeSession(session);
1038                    }
1039    
1040                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1041    
1042                    if (isNew || !DLSyncEventModelImpl.COLUMN_BITMASK_ENABLED) {
1043                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1044                    }
1045    
1046                    EntityCacheUtil.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1047                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey(), dlSyncEvent);
1048    
1049                    clearUniqueFindersCache(dlSyncEvent);
1050                    cacheUniqueFindersCache(dlSyncEvent);
1051    
1052                    return dlSyncEvent;
1053            }
1054    
1055            protected DLSyncEvent toUnwrappedModel(DLSyncEvent dlSyncEvent) {
1056                    if (dlSyncEvent instanceof DLSyncEventImpl) {
1057                            return dlSyncEvent;
1058                    }
1059    
1060                    DLSyncEventImpl dlSyncEventImpl = new DLSyncEventImpl();
1061    
1062                    dlSyncEventImpl.setNew(dlSyncEvent.isNew());
1063                    dlSyncEventImpl.setPrimaryKey(dlSyncEvent.getPrimaryKey());
1064    
1065                    dlSyncEventImpl.setSyncEventId(dlSyncEvent.getSyncEventId());
1066                    dlSyncEventImpl.setModifiedTime(dlSyncEvent.getModifiedTime());
1067                    dlSyncEventImpl.setEvent(dlSyncEvent.getEvent());
1068                    dlSyncEventImpl.setType(dlSyncEvent.getType());
1069                    dlSyncEventImpl.setTypePK(dlSyncEvent.getTypePK());
1070    
1071                    return dlSyncEventImpl;
1072            }
1073    
1074            /**
1075             * Returns the d l sync event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1076             *
1077             * @param primaryKey the primary key of the d l sync event
1078             * @return the d l sync event
1079             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
1080             * @throws SystemException if a system exception occurred
1081             */
1082            @Override
1083            public DLSyncEvent findByPrimaryKey(Serializable primaryKey)
1084                    throws NoSuchSyncEventException, SystemException {
1085                    DLSyncEvent dlSyncEvent = fetchByPrimaryKey(primaryKey);
1086    
1087                    if (dlSyncEvent == null) {
1088                            if (_log.isWarnEnabled()) {
1089                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1090                            }
1091    
1092                            throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1093                                    primaryKey);
1094                    }
1095    
1096                    return dlSyncEvent;
1097            }
1098    
1099            /**
1100             * 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.
1101             *
1102             * @param syncEventId the primary key of the d l sync event
1103             * @return the d l sync event
1104             * @throws com.liferay.portlet.documentlibrary.NoSuchSyncEventException if a d l sync event with the primary key could not be found
1105             * @throws SystemException if a system exception occurred
1106             */
1107            @Override
1108            public DLSyncEvent findByPrimaryKey(long syncEventId)
1109                    throws NoSuchSyncEventException, SystemException {
1110                    return findByPrimaryKey((Serializable)syncEventId);
1111            }
1112    
1113            /**
1114             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1115             *
1116             * @param primaryKey the primary key of the d l sync event
1117             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1118             * @throws SystemException if a system exception occurred
1119             */
1120            @Override
1121            public DLSyncEvent fetchByPrimaryKey(Serializable primaryKey)
1122                    throws SystemException {
1123                    DLSyncEvent dlSyncEvent = (DLSyncEvent)EntityCacheUtil.getResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1124                                    DLSyncEventImpl.class, primaryKey);
1125    
1126                    if (dlSyncEvent == _nullDLSyncEvent) {
1127                            return null;
1128                    }
1129    
1130                    if (dlSyncEvent == null) {
1131                            Session session = null;
1132    
1133                            try {
1134                                    session = openSession();
1135    
1136                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
1137                                                    primaryKey);
1138    
1139                                    if (dlSyncEvent != null) {
1140                                            cacheResult(dlSyncEvent);
1141                                    }
1142                                    else {
1143                                            EntityCacheUtil.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1144                                                    DLSyncEventImpl.class, primaryKey, _nullDLSyncEvent);
1145                                    }
1146                            }
1147                            catch (Exception e) {
1148                                    EntityCacheUtil.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1149                                            DLSyncEventImpl.class, primaryKey);
1150    
1151                                    throw processException(e);
1152                            }
1153                            finally {
1154                                    closeSession(session);
1155                            }
1156                    }
1157    
1158                    return dlSyncEvent;
1159            }
1160    
1161            /**
1162             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1163             *
1164             * @param syncEventId the primary key of the d l sync event
1165             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1166             * @throws SystemException if a system exception occurred
1167             */
1168            @Override
1169            public DLSyncEvent fetchByPrimaryKey(long syncEventId)
1170                    throws SystemException {
1171                    return fetchByPrimaryKey((Serializable)syncEventId);
1172            }
1173    
1174            /**
1175             * Returns all the d l sync events.
1176             *
1177             * @return the d l sync events
1178             * @throws SystemException if a system exception occurred
1179             */
1180            @Override
1181            public List<DLSyncEvent> findAll() throws SystemException {
1182                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1183            }
1184    
1185            /**
1186             * Returns a range of all the d l sync events.
1187             *
1188             * <p>
1189             * 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.
1190             * </p>
1191             *
1192             * @param start the lower bound of the range of d l sync events
1193             * @param end the upper bound of the range of d l sync events (not inclusive)
1194             * @return the range of d l sync events
1195             * @throws SystemException if a system exception occurred
1196             */
1197            @Override
1198            public List<DLSyncEvent> findAll(int start, int end)
1199                    throws SystemException {
1200                    return findAll(start, end, null);
1201            }
1202    
1203            /**
1204             * Returns an ordered range of all the d l sync events.
1205             *
1206             * <p>
1207             * 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.
1208             * </p>
1209             *
1210             * @param start the lower bound of the range of d l sync events
1211             * @param end the upper bound of the range of d l sync events (not inclusive)
1212             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1213             * @return the ordered range of d l sync events
1214             * @throws SystemException if a system exception occurred
1215             */
1216            @Override
1217            public List<DLSyncEvent> findAll(int start, int end,
1218                    OrderByComparator orderByComparator) throws SystemException {
1219                    boolean pagination = true;
1220                    FinderPath finderPath = null;
1221                    Object[] finderArgs = null;
1222    
1223                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1224                                    (orderByComparator == null)) {
1225                            pagination = false;
1226                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1227                            finderArgs = FINDER_ARGS_EMPTY;
1228                    }
1229                    else {
1230                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1231                            finderArgs = new Object[] { start, end, orderByComparator };
1232                    }
1233    
1234                    List<DLSyncEvent> list = (List<DLSyncEvent>)FinderCacheUtil.getResult(finderPath,
1235                                    finderArgs, this);
1236    
1237                    if (list == null) {
1238                            StringBundler query = null;
1239                            String sql = null;
1240    
1241                            if (orderByComparator != null) {
1242                                    query = new StringBundler(2 +
1243                                                    (orderByComparator.getOrderByFields().length * 3));
1244    
1245                                    query.append(_SQL_SELECT_DLSYNCEVENT);
1246    
1247                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1248                                            orderByComparator);
1249    
1250                                    sql = query.toString();
1251                            }
1252                            else {
1253                                    sql = _SQL_SELECT_DLSYNCEVENT;
1254    
1255                                    if (pagination) {
1256                                            sql = sql.concat(DLSyncEventModelImpl.ORDER_BY_JPQL);
1257                                    }
1258                            }
1259    
1260                            Session session = null;
1261    
1262                            try {
1263                                    session = openSession();
1264    
1265                                    Query q = session.createQuery(sql);
1266    
1267                                    if (!pagination) {
1268                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1269                                                            start, end, false);
1270    
1271                                            Collections.sort(list);
1272    
1273                                            list = new UnmodifiableList<DLSyncEvent>(list);
1274                                    }
1275                                    else {
1276                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1277                                                            start, end);
1278                                    }
1279    
1280                                    cacheResult(list);
1281    
1282                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1283                            }
1284                            catch (Exception e) {
1285                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1286    
1287                                    throw processException(e);
1288                            }
1289                            finally {
1290                                    closeSession(session);
1291                            }
1292                    }
1293    
1294                    return list;
1295            }
1296    
1297            /**
1298             * Removes all the d l sync events from the database.
1299             *
1300             * @throws SystemException if a system exception occurred
1301             */
1302            @Override
1303            public void removeAll() throws SystemException {
1304                    for (DLSyncEvent dlSyncEvent : findAll()) {
1305                            remove(dlSyncEvent);
1306                    }
1307            }
1308    
1309            /**
1310             * Returns the number of d l sync events.
1311             *
1312             * @return the number of d l sync events
1313             * @throws SystemException if a system exception occurred
1314             */
1315            @Override
1316            public int countAll() throws SystemException {
1317                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1318                                    FINDER_ARGS_EMPTY, this);
1319    
1320                    if (count == null) {
1321                            Session session = null;
1322    
1323                            try {
1324                                    session = openSession();
1325    
1326                                    Query q = session.createQuery(_SQL_COUNT_DLSYNCEVENT);
1327    
1328                                    count = (Long)q.uniqueResult();
1329    
1330                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1331                                            FINDER_ARGS_EMPTY, count);
1332                            }
1333                            catch (Exception e) {
1334                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1335                                            FINDER_ARGS_EMPTY);
1336    
1337                                    throw processException(e);
1338                            }
1339                            finally {
1340                                    closeSession(session);
1341                            }
1342                    }
1343    
1344                    return count.intValue();
1345            }
1346    
1347            @Override
1348            protected Set<String> getBadColumnNames() {
1349                    return _badColumnNames;
1350            }
1351    
1352            /**
1353             * Initializes the d l sync event persistence.
1354             */
1355            public void afterPropertiesSet() {
1356                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1357                                            com.liferay.portal.util.PropsUtil.get(
1358                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLSyncEvent")));
1359    
1360                    if (listenerClassNames.length > 0) {
1361                            try {
1362                                    List<ModelListener<DLSyncEvent>> listenersList = new ArrayList<ModelListener<DLSyncEvent>>();
1363    
1364                                    for (String listenerClassName : listenerClassNames) {
1365                                            listenersList.add((ModelListener<DLSyncEvent>)InstanceFactory.newInstance(
1366                                                            getClassLoader(), listenerClassName));
1367                                    }
1368    
1369                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1370                            }
1371                            catch (Exception e) {
1372                                    _log.error(e);
1373                            }
1374                    }
1375            }
1376    
1377            public void destroy() {
1378                    EntityCacheUtil.removeCache(DLSyncEventImpl.class.getName());
1379                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1380                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1381                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1382            }
1383    
1384            private static final String _SQL_SELECT_DLSYNCEVENT = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent";
1385            private static final String _SQL_SELECT_DLSYNCEVENT_WHERE = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent WHERE ";
1386            private static final String _SQL_COUNT_DLSYNCEVENT = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent";
1387            private static final String _SQL_COUNT_DLSYNCEVENT_WHERE = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent WHERE ";
1388            private static final String _ORDER_BY_ENTITY_ALIAS = "dlSyncEvent.";
1389            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSyncEvent exists with the primary key ";
1390            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSyncEvent exists with the key {";
1391            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1392            private static Log _log = LogFactoryUtil.getLog(DLSyncEventPersistenceImpl.class);
1393            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1394                                    "type"
1395                            });
1396            private static DLSyncEvent _nullDLSyncEvent = new DLSyncEventImpl() {
1397                            @Override
1398                            public Object clone() {
1399                                    return this;
1400                            }
1401    
1402                            @Override
1403                            public CacheModel<DLSyncEvent> toCacheModel() {
1404                                    return _nullDLSyncEventCacheModel;
1405                            }
1406                    };
1407    
1408            private static CacheModel<DLSyncEvent> _nullDLSyncEventCacheModel = new CacheModel<DLSyncEvent>() {
1409                            @Override
1410                            public DLSyncEvent toEntityModel() {
1411                                    return _nullDLSyncEvent;
1412                            }
1413                    };
1414    }