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