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