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