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