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.setModifiedTime(dlSyncEvent.getModifiedTime());
1067                    dlSyncEventImpl.setEvent(dlSyncEvent.getEvent());
1068                    dlSyncEventImpl.setType(dlSyncEvent.getType());
1069                    dlSyncEventImpl.setTypePK(dlSyncEvent.getTypePK());
1070    
1071                    return dlSyncEventImpl;
1072            }
1073    
1074            /**
1075             * Returns the d l sync event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1076             *
1077             * @param primaryKey the primary key of the d l sync event
1078             * @return the d l sync event
1079             * @throws NoSuchSyncEventException if a d l sync event with the primary key could not be found
1080             */
1081            @Override
1082            public DLSyncEvent findByPrimaryKey(Serializable primaryKey)
1083                    throws NoSuchSyncEventException {
1084                    DLSyncEvent dlSyncEvent = fetchByPrimaryKey(primaryKey);
1085    
1086                    if (dlSyncEvent == null) {
1087                            if (_log.isWarnEnabled()) {
1088                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1089                            }
1090    
1091                            throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1092                                    primaryKey);
1093                    }
1094    
1095                    return dlSyncEvent;
1096            }
1097    
1098            /**
1099             * Returns the d l sync event with the primary key or throws a {@link NoSuchSyncEventException} if it could not be found.
1100             *
1101             * @param syncEventId the primary key of the d l sync event
1102             * @return the d l sync event
1103             * @throws NoSuchSyncEventException if a d l sync event with the primary key could not be found
1104             */
1105            @Override
1106            public DLSyncEvent findByPrimaryKey(long syncEventId)
1107                    throws NoSuchSyncEventException {
1108                    return findByPrimaryKey((Serializable)syncEventId);
1109            }
1110    
1111            /**
1112             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1113             *
1114             * @param primaryKey the primary key of the d l sync event
1115             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1116             */
1117            @Override
1118            public DLSyncEvent fetchByPrimaryKey(Serializable primaryKey) {
1119                    DLSyncEvent dlSyncEvent = (DLSyncEvent)entityCache.getResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1120                                    DLSyncEventImpl.class, primaryKey);
1121    
1122                    if (dlSyncEvent == _nullDLSyncEvent) {
1123                            return null;
1124                    }
1125    
1126                    if (dlSyncEvent == null) {
1127                            Session session = null;
1128    
1129                            try {
1130                                    session = openSession();
1131    
1132                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
1133                                                    primaryKey);
1134    
1135                                    if (dlSyncEvent != null) {
1136                                            cacheResult(dlSyncEvent);
1137                                    }
1138                                    else {
1139                                            entityCache.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1140                                                    DLSyncEventImpl.class, primaryKey, _nullDLSyncEvent);
1141                                    }
1142                            }
1143                            catch (Exception e) {
1144                                    entityCache.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1145                                            DLSyncEventImpl.class, primaryKey);
1146    
1147                                    throw processException(e);
1148                            }
1149                            finally {
1150                                    closeSession(session);
1151                            }
1152                    }
1153    
1154                    return dlSyncEvent;
1155            }
1156    
1157            /**
1158             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1159             *
1160             * @param syncEventId the primary key of the d l sync event
1161             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1162             */
1163            @Override
1164            public DLSyncEvent fetchByPrimaryKey(long syncEventId) {
1165                    return fetchByPrimaryKey((Serializable)syncEventId);
1166            }
1167    
1168            @Override
1169            public Map<Serializable, DLSyncEvent> fetchByPrimaryKeys(
1170                    Set<Serializable> primaryKeys) {
1171                    if (primaryKeys.isEmpty()) {
1172                            return Collections.emptyMap();
1173                    }
1174    
1175                    Map<Serializable, DLSyncEvent> map = new HashMap<Serializable, DLSyncEvent>();
1176    
1177                    if (primaryKeys.size() == 1) {
1178                            Iterator<Serializable> iterator = primaryKeys.iterator();
1179    
1180                            Serializable primaryKey = iterator.next();
1181    
1182                            DLSyncEvent dlSyncEvent = fetchByPrimaryKey(primaryKey);
1183    
1184                            if (dlSyncEvent != null) {
1185                                    map.put(primaryKey, dlSyncEvent);
1186                            }
1187    
1188                            return map;
1189                    }
1190    
1191                    Set<Serializable> uncachedPrimaryKeys = null;
1192    
1193                    for (Serializable primaryKey : primaryKeys) {
1194                            DLSyncEvent dlSyncEvent = (DLSyncEvent)entityCache.getResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1195                                            DLSyncEventImpl.class, primaryKey);
1196    
1197                            if (dlSyncEvent == null) {
1198                                    if (uncachedPrimaryKeys == null) {
1199                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1200                                    }
1201    
1202                                    uncachedPrimaryKeys.add(primaryKey);
1203                            }
1204                            else {
1205                                    map.put(primaryKey, dlSyncEvent);
1206                            }
1207                    }
1208    
1209                    if (uncachedPrimaryKeys == null) {
1210                            return map;
1211                    }
1212    
1213                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1214                                    1);
1215    
1216                    query.append(_SQL_SELECT_DLSYNCEVENT_WHERE_PKS_IN);
1217    
1218                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1219                            query.append(String.valueOf(primaryKey));
1220    
1221                            query.append(StringPool.COMMA);
1222                    }
1223    
1224                    query.setIndex(query.index() - 1);
1225    
1226                    query.append(StringPool.CLOSE_PARENTHESIS);
1227    
1228                    String sql = query.toString();
1229    
1230                    Session session = null;
1231    
1232                    try {
1233                            session = openSession();
1234    
1235                            Query q = session.createQuery(sql);
1236    
1237                            for (DLSyncEvent dlSyncEvent : (List<DLSyncEvent>)q.list()) {
1238                                    map.put(dlSyncEvent.getPrimaryKeyObj(), dlSyncEvent);
1239    
1240                                    cacheResult(dlSyncEvent);
1241    
1242                                    uncachedPrimaryKeys.remove(dlSyncEvent.getPrimaryKeyObj());
1243                            }
1244    
1245                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1246                                    entityCache.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1247                                            DLSyncEventImpl.class, primaryKey, _nullDLSyncEvent);
1248                            }
1249                    }
1250                    catch (Exception e) {
1251                            throw processException(e);
1252                    }
1253                    finally {
1254                            closeSession(session);
1255                    }
1256    
1257                    return map;
1258            }
1259    
1260            /**
1261             * Returns all the d l sync events.
1262             *
1263             * @return the d l sync events
1264             */
1265            @Override
1266            public List<DLSyncEvent> findAll() {
1267                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1268            }
1269    
1270            /**
1271             * Returns a range of all the d l sync events.
1272             *
1273             * <p>
1274             * 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.
1275             * </p>
1276             *
1277             * @param start the lower bound of the range of d l sync events
1278             * @param end the upper bound of the range of d l sync events (not inclusive)
1279             * @return the range of d l sync events
1280             */
1281            @Override
1282            public List<DLSyncEvent> findAll(int start, int end) {
1283                    return findAll(start, end, null);
1284            }
1285    
1286            /**
1287             * Returns an ordered range of all the d l sync events.
1288             *
1289             * <p>
1290             * 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.
1291             * </p>
1292             *
1293             * @param start the lower bound of the range of d l sync events
1294             * @param end the upper bound of the range of d l sync events (not inclusive)
1295             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1296             * @return the ordered range of d l sync events
1297             */
1298            @Override
1299            public List<DLSyncEvent> findAll(int start, int end,
1300                    OrderByComparator<DLSyncEvent> orderByComparator) {
1301                    return findAll(start, end, orderByComparator, true);
1302            }
1303    
1304            /**
1305             * Returns an ordered range of all the d l sync events.
1306             *
1307             * <p>
1308             * 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.
1309             * </p>
1310             *
1311             * @param start the lower bound of the range of d l sync events
1312             * @param end the upper bound of the range of d l sync events (not inclusive)
1313             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1314             * @param retrieveFromCache whether to retrieve from the finder cache
1315             * @return the ordered range of d l sync events
1316             */
1317            @Override
1318            public List<DLSyncEvent> findAll(int start, int end,
1319                    OrderByComparator<DLSyncEvent> orderByComparator,
1320                    boolean retrieveFromCache) {
1321                    boolean pagination = true;
1322                    FinderPath finderPath = null;
1323                    Object[] finderArgs = null;
1324    
1325                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1326                                    (orderByComparator == null)) {
1327                            pagination = false;
1328                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1329                            finderArgs = FINDER_ARGS_EMPTY;
1330                    }
1331                    else {
1332                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1333                            finderArgs = new Object[] { start, end, orderByComparator };
1334                    }
1335    
1336                    List<DLSyncEvent> list = null;
1337    
1338                    if (retrieveFromCache) {
1339                            list = (List<DLSyncEvent>)finderCache.getResult(finderPath,
1340                                            finderArgs, this);
1341                    }
1342    
1343                    if (list == null) {
1344                            StringBundler query = null;
1345                            String sql = null;
1346    
1347                            if (orderByComparator != null) {
1348                                    query = new StringBundler(2 +
1349                                                    (orderByComparator.getOrderByFields().length * 3));
1350    
1351                                    query.append(_SQL_SELECT_DLSYNCEVENT);
1352    
1353                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1354                                            orderByComparator);
1355    
1356                                    sql = query.toString();
1357                            }
1358                            else {
1359                                    sql = _SQL_SELECT_DLSYNCEVENT;
1360    
1361                                    if (pagination) {
1362                                            sql = sql.concat(DLSyncEventModelImpl.ORDER_BY_JPQL);
1363                                    }
1364                            }
1365    
1366                            Session session = null;
1367    
1368                            try {
1369                                    session = openSession();
1370    
1371                                    Query q = session.createQuery(sql);
1372    
1373                                    if (!pagination) {
1374                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1375                                                            start, end, false);
1376    
1377                                            Collections.sort(list);
1378    
1379                                            list = Collections.unmodifiableList(list);
1380                                    }
1381                                    else {
1382                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1383                                                            start, end);
1384                                    }
1385    
1386                                    cacheResult(list);
1387    
1388                                    finderCache.putResult(finderPath, finderArgs, list);
1389                            }
1390                            catch (Exception e) {
1391                                    finderCache.removeResult(finderPath, finderArgs);
1392    
1393                                    throw processException(e);
1394                            }
1395                            finally {
1396                                    closeSession(session);
1397                            }
1398                    }
1399    
1400                    return list;
1401            }
1402    
1403            /**
1404             * Removes all the d l sync events from the database.
1405             *
1406             */
1407            @Override
1408            public void removeAll() {
1409                    for (DLSyncEvent dlSyncEvent : findAll()) {
1410                            remove(dlSyncEvent);
1411                    }
1412            }
1413    
1414            /**
1415             * Returns the number of d l sync events.
1416             *
1417             * @return the number of d l sync events
1418             */
1419            @Override
1420            public int countAll() {
1421                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1422                                    FINDER_ARGS_EMPTY, this);
1423    
1424                    if (count == null) {
1425                            Session session = null;
1426    
1427                            try {
1428                                    session = openSession();
1429    
1430                                    Query q = session.createQuery(_SQL_COUNT_DLSYNCEVENT);
1431    
1432                                    count = (Long)q.uniqueResult();
1433    
1434                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1435                                            count);
1436                            }
1437                            catch (Exception e) {
1438                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1439                                            FINDER_ARGS_EMPTY);
1440    
1441                                    throw processException(e);
1442                            }
1443                            finally {
1444                                    closeSession(session);
1445                            }
1446                    }
1447    
1448                    return count.intValue();
1449            }
1450    
1451            @Override
1452            public Set<String> getBadColumnNames() {
1453                    return _badColumnNames;
1454            }
1455    
1456            @Override
1457            protected Map<String, Integer> getTableColumnsMap() {
1458                    return DLSyncEventModelImpl.TABLE_COLUMNS_MAP;
1459            }
1460    
1461            /**
1462             * Initializes the d l sync event persistence.
1463             */
1464            public void afterPropertiesSet() {
1465            }
1466    
1467            public void destroy() {
1468                    entityCache.removeCache(DLSyncEventImpl.class.getName());
1469                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1470                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1471                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1472            }
1473    
1474            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1475            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1476            private static final String _SQL_SELECT_DLSYNCEVENT = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent";
1477            private static final String _SQL_SELECT_DLSYNCEVENT_WHERE_PKS_IN = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent WHERE syncEventId IN (";
1478            private static final String _SQL_SELECT_DLSYNCEVENT_WHERE = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent WHERE ";
1479            private static final String _SQL_COUNT_DLSYNCEVENT = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent";
1480            private static final String _SQL_COUNT_DLSYNCEVENT_WHERE = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent WHERE ";
1481            private static final String _ORDER_BY_ENTITY_ALIAS = "dlSyncEvent.";
1482            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSyncEvent exists with the primary key ";
1483            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSyncEvent exists with the key {";
1484            private static final Log _log = LogFactoryUtil.getLog(DLSyncEventPersistenceImpl.class);
1485            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1486                                    "type"
1487                            });
1488            private static final DLSyncEvent _nullDLSyncEvent = new DLSyncEventImpl() {
1489                            @Override
1490                            public Object clone() {
1491                                    return this;
1492                            }
1493    
1494                            @Override
1495                            public CacheModel<DLSyncEvent> toCacheModel() {
1496                                    return _nullDLSyncEventCacheModel;
1497                            }
1498                    };
1499    
1500            private static final CacheModel<DLSyncEvent> _nullDLSyncEventCacheModel = new CacheModel<DLSyncEvent>() {
1501                            @Override
1502                            public DLSyncEvent toEntityModel() {
1503                                    return _nullDLSyncEvent;
1504                            }
1505                    };
1506    }