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