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 * 2));
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(4 +
420                                            (orderByComparator.getOrderByConditionFields().length * 3) +
421                                            (orderByComparator.getOrderByFields().length * 3));
422                    }
423                    else {
424                            query = new StringBundler(3);
425                    }
426    
427                    query.append(_SQL_SELECT_DLSYNCEVENT_WHERE);
428    
429                    query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2);
430    
431                    if (orderByComparator != null) {
432                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
433    
434                            if (orderByConditionFields.length > 0) {
435                                    query.append(WHERE_AND);
436                            }
437    
438                            for (int i = 0; i < orderByConditionFields.length; i++) {
439                                    query.append(_ORDER_BY_ENTITY_ALIAS);
440                                    query.append(orderByConditionFields[i]);
441    
442                                    if ((i + 1) < orderByConditionFields.length) {
443                                            if (orderByComparator.isAscending() ^ previous) {
444                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
445                                            }
446                                            else {
447                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
448                                            }
449                                    }
450                                    else {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN);
456                                            }
457                                    }
458                            }
459    
460                            query.append(ORDER_BY_CLAUSE);
461    
462                            String[] orderByFields = orderByComparator.getOrderByFields();
463    
464                            for (int i = 0; i < orderByFields.length; i++) {
465                                    query.append(_ORDER_BY_ENTITY_ALIAS);
466                                    query.append(orderByFields[i]);
467    
468                                    if ((i + 1) < orderByFields.length) {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
471                                            }
472                                            else {
473                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
474                                            }
475                                    }
476                                    else {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC);
482                                            }
483                                    }
484                            }
485                    }
486                    else {
487                            query.append(DLSyncEventModelImpl.ORDER_BY_JPQL);
488                    }
489    
490                    String sql = query.toString();
491    
492                    Query q = session.createQuery(sql);
493    
494                    q.setFirstResult(0);
495                    q.setMaxResults(2);
496    
497                    QueryPos qPos = QueryPos.getInstance(q);
498    
499                    qPos.add(modifiedTime);
500    
501                    if (orderByComparator != null) {
502                            Object[] values = orderByComparator.getOrderByConditionValues(dlSyncEvent);
503    
504                            for (Object value : values) {
505                                    qPos.add(value);
506                            }
507                    }
508    
509                    List<DLSyncEvent> list = q.list();
510    
511                    if (list.size() == 2) {
512                            return list.get(1);
513                    }
514                    else {
515                            return null;
516                    }
517            }
518    
519            /**
520             * Removes all the d l sync events where modifiedTime &gt; &#63; from the database.
521             *
522             * @param modifiedTime the modified time
523             */
524            @Override
525            public void removeByModifiedTime(long modifiedTime) {
526                    for (DLSyncEvent dlSyncEvent : findByModifiedTime(modifiedTime,
527                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
528                            remove(dlSyncEvent);
529                    }
530            }
531    
532            /**
533             * Returns the number of d l sync events where modifiedTime &gt; &#63;.
534             *
535             * @param modifiedTime the modified time
536             * @return the number of matching d l sync events
537             */
538            @Override
539            public int countByModifiedTime(long modifiedTime) {
540                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_MODIFIEDTIME;
541    
542                    Object[] finderArgs = new Object[] { modifiedTime };
543    
544                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
545    
546                    if (count == null) {
547                            StringBundler query = new StringBundler(2);
548    
549                            query.append(_SQL_COUNT_DLSYNCEVENT_WHERE);
550    
551                            query.append(_FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2);
552    
553                            String sql = query.toString();
554    
555                            Session session = null;
556    
557                            try {
558                                    session = openSession();
559    
560                                    Query q = session.createQuery(sql);
561    
562                                    QueryPos qPos = QueryPos.getInstance(q);
563    
564                                    qPos.add(modifiedTime);
565    
566                                    count = (Long)q.uniqueResult();
567    
568                                    finderCache.putResult(finderPath, finderArgs, count);
569                            }
570                            catch (Exception e) {
571                                    finderCache.removeResult(finderPath, finderArgs);
572    
573                                    throw processException(e);
574                            }
575                            finally {
576                                    closeSession(session);
577                            }
578                    }
579    
580                    return count.intValue();
581            }
582    
583            private static final String _FINDER_COLUMN_MODIFIEDTIME_MODIFIEDTIME_2 = "dlSyncEvent.modifiedTime > ?";
584            public static final FinderPath FINDER_PATH_FETCH_BY_TYPEPK = new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
585                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, DLSyncEventImpl.class,
586                            FINDER_CLASS_NAME_ENTITY, "fetchByTypePK",
587                            new String[] { Long.class.getName() },
588                            DLSyncEventModelImpl.TYPEPK_COLUMN_BITMASK);
589            public static final FinderPath FINDER_PATH_COUNT_BY_TYPEPK = new FinderPath(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
590                            DLSyncEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
591                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTypePK",
592                            new String[] { Long.class.getName() });
593    
594            /**
595             * Returns the d l sync event where typePK = &#63; or throws a {@link NoSuchSyncEventException} if it could not be found.
596             *
597             * @param typePK the type p k
598             * @return the matching d l sync event
599             * @throws NoSuchSyncEventException if a matching d l sync event could not be found
600             */
601            @Override
602            public DLSyncEvent findByTypePK(long typePK)
603                    throws NoSuchSyncEventException {
604                    DLSyncEvent dlSyncEvent = fetchByTypePK(typePK);
605    
606                    if (dlSyncEvent == null) {
607                            StringBundler msg = new StringBundler(4);
608    
609                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
610    
611                            msg.append("typePK=");
612                            msg.append(typePK);
613    
614                            msg.append(StringPool.CLOSE_CURLY_BRACE);
615    
616                            if (_log.isWarnEnabled()) {
617                                    _log.warn(msg.toString());
618                            }
619    
620                            throw new NoSuchSyncEventException(msg.toString());
621                    }
622    
623                    return dlSyncEvent;
624            }
625    
626            /**
627             * Returns the d l sync event where typePK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
628             *
629             * @param typePK the type p k
630             * @return the matching d l sync event, or <code>null</code> if a matching d l sync event could not be found
631             */
632            @Override
633            public DLSyncEvent fetchByTypePK(long typePK) {
634                    return fetchByTypePK(typePK, true);
635            }
636    
637            /**
638             * 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.
639             *
640             * @param typePK the type p k
641             * @param retrieveFromCache whether to retrieve from the finder cache
642             * @return the matching d l sync event, or <code>null</code> if a matching d l sync event could not be found
643             */
644            @Override
645            public DLSyncEvent fetchByTypePK(long typePK, boolean retrieveFromCache) {
646                    Object[] finderArgs = new Object[] { typePK };
647    
648                    Object result = null;
649    
650                    if (retrieveFromCache) {
651                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_TYPEPK,
652                                            finderArgs, this);
653                    }
654    
655                    if (result instanceof DLSyncEvent) {
656                            DLSyncEvent dlSyncEvent = (DLSyncEvent)result;
657    
658                            if ((typePK != dlSyncEvent.getTypePK())) {
659                                    result = null;
660                            }
661                    }
662    
663                    if (result == null) {
664                            StringBundler query = new StringBundler(3);
665    
666                            query.append(_SQL_SELECT_DLSYNCEVENT_WHERE);
667    
668                            query.append(_FINDER_COLUMN_TYPEPK_TYPEPK_2);
669    
670                            String sql = query.toString();
671    
672                            Session session = null;
673    
674                            try {
675                                    session = openSession();
676    
677                                    Query q = session.createQuery(sql);
678    
679                                    QueryPos qPos = QueryPos.getInstance(q);
680    
681                                    qPos.add(typePK);
682    
683                                    List<DLSyncEvent> list = q.list();
684    
685                                    if (list.isEmpty()) {
686                                            finderCache.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
687                                                    finderArgs, list);
688                                    }
689                                    else {
690                                            DLSyncEvent dlSyncEvent = list.get(0);
691    
692                                            result = dlSyncEvent;
693    
694                                            cacheResult(dlSyncEvent);
695    
696                                            if ((dlSyncEvent.getTypePK() != typePK)) {
697                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
698                                                            finderArgs, dlSyncEvent);
699                                            }
700                                    }
701                            }
702                            catch (Exception e) {
703                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, finderArgs);
704    
705                                    throw processException(e);
706                            }
707                            finally {
708                                    closeSession(session);
709                            }
710                    }
711    
712                    if (result instanceof List<?>) {
713                            return null;
714                    }
715                    else {
716                            return (DLSyncEvent)result;
717                    }
718            }
719    
720            /**
721             * Removes the d l sync event where typePK = &#63; from the database.
722             *
723             * @param typePK the type p k
724             * @return the d l sync event that was removed
725             */
726            @Override
727            public DLSyncEvent removeByTypePK(long typePK)
728                    throws NoSuchSyncEventException {
729                    DLSyncEvent dlSyncEvent = findByTypePK(typePK);
730    
731                    return remove(dlSyncEvent);
732            }
733    
734            /**
735             * Returns the number of d l sync events where typePK = &#63;.
736             *
737             * @param typePK the type p k
738             * @return the number of matching d l sync events
739             */
740            @Override
741            public int countByTypePK(long typePK) {
742                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPEPK;
743    
744                    Object[] finderArgs = new Object[] { typePK };
745    
746                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
747    
748                    if (count == null) {
749                            StringBundler query = new StringBundler(2);
750    
751                            query.append(_SQL_COUNT_DLSYNCEVENT_WHERE);
752    
753                            query.append(_FINDER_COLUMN_TYPEPK_TYPEPK_2);
754    
755                            String sql = query.toString();
756    
757                            Session session = null;
758    
759                            try {
760                                    session = openSession();
761    
762                                    Query q = session.createQuery(sql);
763    
764                                    QueryPos qPos = QueryPos.getInstance(q);
765    
766                                    qPos.add(typePK);
767    
768                                    count = (Long)q.uniqueResult();
769    
770                                    finderCache.putResult(finderPath, finderArgs, count);
771                            }
772                            catch (Exception e) {
773                                    finderCache.removeResult(finderPath, finderArgs);
774    
775                                    throw processException(e);
776                            }
777                            finally {
778                                    closeSession(session);
779                            }
780                    }
781    
782                    return count.intValue();
783            }
784    
785            private static final String _FINDER_COLUMN_TYPEPK_TYPEPK_2 = "dlSyncEvent.typePK = ?";
786    
787            public DLSyncEventPersistenceImpl() {
788                    setModelClass(DLSyncEvent.class);
789            }
790    
791            /**
792             * Caches the d l sync event in the entity cache if it is enabled.
793             *
794             * @param dlSyncEvent the d l sync event
795             */
796            @Override
797            public void cacheResult(DLSyncEvent dlSyncEvent) {
798                    entityCache.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
799                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey(), dlSyncEvent);
800    
801                    finderCache.putResult(FINDER_PATH_FETCH_BY_TYPEPK,
802                            new Object[] { dlSyncEvent.getTypePK() }, dlSyncEvent);
803    
804                    dlSyncEvent.resetOriginalValues();
805            }
806    
807            /**
808             * Caches the d l sync events in the entity cache if it is enabled.
809             *
810             * @param dlSyncEvents the d l sync events
811             */
812            @Override
813            public void cacheResult(List<DLSyncEvent> dlSyncEvents) {
814                    for (DLSyncEvent dlSyncEvent : dlSyncEvents) {
815                            if (entityCache.getResult(
816                                                    DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
817                                                    DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey()) == null) {
818                                    cacheResult(dlSyncEvent);
819                            }
820                            else {
821                                    dlSyncEvent.resetOriginalValues();
822                            }
823                    }
824            }
825    
826            /**
827             * Clears the cache for all d l sync events.
828             *
829             * <p>
830             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
831             * </p>
832             */
833            @Override
834            public void clearCache() {
835                    entityCache.clearCache(DLSyncEventImpl.class);
836    
837                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
838                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
839                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
840            }
841    
842            /**
843             * Clears the cache for the d l sync event.
844             *
845             * <p>
846             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
847             * </p>
848             */
849            @Override
850            public void clearCache(DLSyncEvent dlSyncEvent) {
851                    entityCache.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
852                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey());
853    
854                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
855                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
856    
857                    clearUniqueFindersCache((DLSyncEventModelImpl)dlSyncEvent);
858            }
859    
860            @Override
861            public void clearCache(List<DLSyncEvent> dlSyncEvents) {
862                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
863                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
864    
865                    for (DLSyncEvent dlSyncEvent : dlSyncEvents) {
866                            entityCache.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
867                                    DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey());
868    
869                            clearUniqueFindersCache((DLSyncEventModelImpl)dlSyncEvent);
870                    }
871            }
872    
873            protected void cacheUniqueFindersCache(
874                    DLSyncEventModelImpl dlSyncEventModelImpl, boolean isNew) {
875                    if (isNew) {
876                            Object[] args = new Object[] { dlSyncEventModelImpl.getTypePK() };
877    
878                            finderCache.putResult(FINDER_PATH_COUNT_BY_TYPEPK, args,
879                                    Long.valueOf(1));
880                            finderCache.putResult(FINDER_PATH_FETCH_BY_TYPEPK, args,
881                                    dlSyncEventModelImpl);
882                    }
883                    else {
884                            if ((dlSyncEventModelImpl.getColumnBitmask() &
885                                            FINDER_PATH_FETCH_BY_TYPEPK.getColumnBitmask()) != 0) {
886                                    Object[] args = new Object[] { dlSyncEventModelImpl.getTypePK() };
887    
888                                    finderCache.putResult(FINDER_PATH_COUNT_BY_TYPEPK, args,
889                                            Long.valueOf(1));
890                                    finderCache.putResult(FINDER_PATH_FETCH_BY_TYPEPK, args,
891                                            dlSyncEventModelImpl);
892                            }
893                    }
894            }
895    
896            protected void clearUniqueFindersCache(
897                    DLSyncEventModelImpl dlSyncEventModelImpl) {
898                    Object[] args = new Object[] { dlSyncEventModelImpl.getTypePK() };
899    
900                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPEPK, args);
901                    finderCache.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, args);
902    
903                    if ((dlSyncEventModelImpl.getColumnBitmask() &
904                                    FINDER_PATH_FETCH_BY_TYPEPK.getColumnBitmask()) != 0) {
905                            args = new Object[] { dlSyncEventModelImpl.getOriginalTypePK() };
906    
907                            finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPEPK, args);
908                            finderCache.removeResult(FINDER_PATH_FETCH_BY_TYPEPK, args);
909                    }
910            }
911    
912            /**
913             * Creates a new d l sync event with the primary key. Does not add the d l sync event to the database.
914             *
915             * @param syncEventId the primary key for the new d l sync event
916             * @return the new d l sync event
917             */
918            @Override
919            public DLSyncEvent create(long syncEventId) {
920                    DLSyncEvent dlSyncEvent = new DLSyncEventImpl();
921    
922                    dlSyncEvent.setNew(true);
923                    dlSyncEvent.setPrimaryKey(syncEventId);
924    
925                    dlSyncEvent.setCompanyId(companyProvider.getCompanyId());
926    
927                    return dlSyncEvent;
928            }
929    
930            /**
931             * Removes the d l sync event with the primary key from the database. Also notifies the appropriate model listeners.
932             *
933             * @param syncEventId the primary key of the d l sync event
934             * @return the d l sync event that was removed
935             * @throws NoSuchSyncEventException if a d l sync event with the primary key could not be found
936             */
937            @Override
938            public DLSyncEvent remove(long syncEventId) throws NoSuchSyncEventException {
939                    return remove((Serializable)syncEventId);
940            }
941    
942            /**
943             * Removes the d l sync event with the primary key from the database. Also notifies the appropriate model listeners.
944             *
945             * @param primaryKey the primary key of the d l sync event
946             * @return the d l sync event that was removed
947             * @throws NoSuchSyncEventException if a d l sync event with the primary key could not be found
948             */
949            @Override
950            public DLSyncEvent remove(Serializable primaryKey)
951                    throws NoSuchSyncEventException {
952                    Session session = null;
953    
954                    try {
955                            session = openSession();
956    
957                            DLSyncEvent dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
958                                            primaryKey);
959    
960                            if (dlSyncEvent == null) {
961                                    if (_log.isWarnEnabled()) {
962                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
963                                    }
964    
965                                    throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
966                                            primaryKey);
967                            }
968    
969                            return remove(dlSyncEvent);
970                    }
971                    catch (NoSuchSyncEventException nsee) {
972                            throw nsee;
973                    }
974                    catch (Exception e) {
975                            throw processException(e);
976                    }
977                    finally {
978                            closeSession(session);
979                    }
980            }
981    
982            @Override
983            protected DLSyncEvent removeImpl(DLSyncEvent dlSyncEvent) {
984                    dlSyncEvent = toUnwrappedModel(dlSyncEvent);
985    
986                    Session session = null;
987    
988                    try {
989                            session = openSession();
990    
991                            if (!session.contains(dlSyncEvent)) {
992                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
993                                                    dlSyncEvent.getPrimaryKeyObj());
994                            }
995    
996                            if (dlSyncEvent != null) {
997                                    session.delete(dlSyncEvent);
998                            }
999                    }
1000                    catch (Exception e) {
1001                            throw processException(e);
1002                    }
1003                    finally {
1004                            closeSession(session);
1005                    }
1006    
1007                    if (dlSyncEvent != null) {
1008                            clearCache(dlSyncEvent);
1009                    }
1010    
1011                    return dlSyncEvent;
1012            }
1013    
1014            @Override
1015            public DLSyncEvent updateImpl(DLSyncEvent dlSyncEvent) {
1016                    dlSyncEvent = toUnwrappedModel(dlSyncEvent);
1017    
1018                    boolean isNew = dlSyncEvent.isNew();
1019    
1020                    DLSyncEventModelImpl dlSyncEventModelImpl = (DLSyncEventModelImpl)dlSyncEvent;
1021    
1022                    Session session = null;
1023    
1024                    try {
1025                            session = openSession();
1026    
1027                            if (dlSyncEvent.isNew()) {
1028                                    session.save(dlSyncEvent);
1029    
1030                                    dlSyncEvent.setNew(false);
1031                            }
1032                            else {
1033                                    dlSyncEvent = (DLSyncEvent)session.merge(dlSyncEvent);
1034                            }
1035                    }
1036                    catch (Exception e) {
1037                            throw processException(e);
1038                    }
1039                    finally {
1040                            closeSession(session);
1041                    }
1042    
1043                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1044    
1045                    if (isNew || !DLSyncEventModelImpl.COLUMN_BITMASK_ENABLED) {
1046                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1047                    }
1048    
1049                    entityCache.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1050                            DLSyncEventImpl.class, dlSyncEvent.getPrimaryKey(), dlSyncEvent,
1051                            false);
1052    
1053                    clearUniqueFindersCache(dlSyncEventModelImpl);
1054                    cacheUniqueFindersCache(dlSyncEventModelImpl, isNew);
1055    
1056                    dlSyncEvent.resetOriginalValues();
1057    
1058                    return dlSyncEvent;
1059            }
1060    
1061            protected DLSyncEvent toUnwrappedModel(DLSyncEvent dlSyncEvent) {
1062                    if (dlSyncEvent instanceof DLSyncEventImpl) {
1063                            return dlSyncEvent;
1064                    }
1065    
1066                    DLSyncEventImpl dlSyncEventImpl = new DLSyncEventImpl();
1067    
1068                    dlSyncEventImpl.setNew(dlSyncEvent.isNew());
1069                    dlSyncEventImpl.setPrimaryKey(dlSyncEvent.getPrimaryKey());
1070    
1071                    dlSyncEventImpl.setSyncEventId(dlSyncEvent.getSyncEventId());
1072                    dlSyncEventImpl.setCompanyId(dlSyncEvent.getCompanyId());
1073                    dlSyncEventImpl.setModifiedTime(dlSyncEvent.getModifiedTime());
1074                    dlSyncEventImpl.setEvent(dlSyncEvent.getEvent());
1075                    dlSyncEventImpl.setType(dlSyncEvent.getType());
1076                    dlSyncEventImpl.setTypePK(dlSyncEvent.getTypePK());
1077    
1078                    return dlSyncEventImpl;
1079            }
1080    
1081            /**
1082             * 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.
1083             *
1084             * @param primaryKey the primary key of the d l sync event
1085             * @return the d l sync event
1086             * @throws NoSuchSyncEventException if a d l sync event with the primary key could not be found
1087             */
1088            @Override
1089            public DLSyncEvent findByPrimaryKey(Serializable primaryKey)
1090                    throws NoSuchSyncEventException {
1091                    DLSyncEvent dlSyncEvent = fetchByPrimaryKey(primaryKey);
1092    
1093                    if (dlSyncEvent == null) {
1094                            if (_log.isWarnEnabled()) {
1095                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1096                            }
1097    
1098                            throw new NoSuchSyncEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1099                                    primaryKey);
1100                    }
1101    
1102                    return dlSyncEvent;
1103            }
1104    
1105            /**
1106             * Returns the d l sync event with the primary key or throws a {@link NoSuchSyncEventException} if it could not be found.
1107             *
1108             * @param syncEventId the primary key of the d l sync event
1109             * @return the d l sync event
1110             * @throws NoSuchSyncEventException if a d l sync event with the primary key could not be found
1111             */
1112            @Override
1113            public DLSyncEvent findByPrimaryKey(long syncEventId)
1114                    throws NoSuchSyncEventException {
1115                    return findByPrimaryKey((Serializable)syncEventId);
1116            }
1117    
1118            /**
1119             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1120             *
1121             * @param primaryKey the primary key of the d l sync event
1122             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1123             */
1124            @Override
1125            public DLSyncEvent fetchByPrimaryKey(Serializable primaryKey) {
1126                    DLSyncEvent dlSyncEvent = (DLSyncEvent)entityCache.getResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1127                                    DLSyncEventImpl.class, primaryKey);
1128    
1129                    if (dlSyncEvent == _nullDLSyncEvent) {
1130                            return null;
1131                    }
1132    
1133                    if (dlSyncEvent == null) {
1134                            Session session = null;
1135    
1136                            try {
1137                                    session = openSession();
1138    
1139                                    dlSyncEvent = (DLSyncEvent)session.get(DLSyncEventImpl.class,
1140                                                    primaryKey);
1141    
1142                                    if (dlSyncEvent != null) {
1143                                            cacheResult(dlSyncEvent);
1144                                    }
1145                                    else {
1146                                            entityCache.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1147                                                    DLSyncEventImpl.class, primaryKey, _nullDLSyncEvent);
1148                                    }
1149                            }
1150                            catch (Exception e) {
1151                                    entityCache.removeResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1152                                            DLSyncEventImpl.class, primaryKey);
1153    
1154                                    throw processException(e);
1155                            }
1156                            finally {
1157                                    closeSession(session);
1158                            }
1159                    }
1160    
1161                    return dlSyncEvent;
1162            }
1163    
1164            /**
1165             * Returns the d l sync event with the primary key or returns <code>null</code> if it could not be found.
1166             *
1167             * @param syncEventId the primary key of the d l sync event
1168             * @return the d l sync event, or <code>null</code> if a d l sync event with the primary key could not be found
1169             */
1170            @Override
1171            public DLSyncEvent fetchByPrimaryKey(long syncEventId) {
1172                    return fetchByPrimaryKey((Serializable)syncEventId);
1173            }
1174    
1175            @Override
1176            public Map<Serializable, DLSyncEvent> fetchByPrimaryKeys(
1177                    Set<Serializable> primaryKeys) {
1178                    if (primaryKeys.isEmpty()) {
1179                            return Collections.emptyMap();
1180                    }
1181    
1182                    Map<Serializable, DLSyncEvent> map = new HashMap<Serializable, DLSyncEvent>();
1183    
1184                    if (primaryKeys.size() == 1) {
1185                            Iterator<Serializable> iterator = primaryKeys.iterator();
1186    
1187                            Serializable primaryKey = iterator.next();
1188    
1189                            DLSyncEvent dlSyncEvent = fetchByPrimaryKey(primaryKey);
1190    
1191                            if (dlSyncEvent != null) {
1192                                    map.put(primaryKey, dlSyncEvent);
1193                            }
1194    
1195                            return map;
1196                    }
1197    
1198                    Set<Serializable> uncachedPrimaryKeys = null;
1199    
1200                    for (Serializable primaryKey : primaryKeys) {
1201                            DLSyncEvent dlSyncEvent = (DLSyncEvent)entityCache.getResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1202                                            DLSyncEventImpl.class, primaryKey);
1203    
1204                            if (dlSyncEvent == null) {
1205                                    if (uncachedPrimaryKeys == null) {
1206                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1207                                    }
1208    
1209                                    uncachedPrimaryKeys.add(primaryKey);
1210                            }
1211                            else {
1212                                    map.put(primaryKey, dlSyncEvent);
1213                            }
1214                    }
1215    
1216                    if (uncachedPrimaryKeys == null) {
1217                            return map;
1218                    }
1219    
1220                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1221                                    1);
1222    
1223                    query.append(_SQL_SELECT_DLSYNCEVENT_WHERE_PKS_IN);
1224    
1225                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1226                            query.append(String.valueOf(primaryKey));
1227    
1228                            query.append(StringPool.COMMA);
1229                    }
1230    
1231                    query.setIndex(query.index() - 1);
1232    
1233                    query.append(StringPool.CLOSE_PARENTHESIS);
1234    
1235                    String sql = query.toString();
1236    
1237                    Session session = null;
1238    
1239                    try {
1240                            session = openSession();
1241    
1242                            Query q = session.createQuery(sql);
1243    
1244                            for (DLSyncEvent dlSyncEvent : (List<DLSyncEvent>)q.list()) {
1245                                    map.put(dlSyncEvent.getPrimaryKeyObj(), dlSyncEvent);
1246    
1247                                    cacheResult(dlSyncEvent);
1248    
1249                                    uncachedPrimaryKeys.remove(dlSyncEvent.getPrimaryKeyObj());
1250                            }
1251    
1252                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1253                                    entityCache.putResult(DLSyncEventModelImpl.ENTITY_CACHE_ENABLED,
1254                                            DLSyncEventImpl.class, primaryKey, _nullDLSyncEvent);
1255                            }
1256                    }
1257                    catch (Exception e) {
1258                            throw processException(e);
1259                    }
1260                    finally {
1261                            closeSession(session);
1262                    }
1263    
1264                    return map;
1265            }
1266    
1267            /**
1268             * Returns all the d l sync events.
1269             *
1270             * @return the d l sync events
1271             */
1272            @Override
1273            public List<DLSyncEvent> findAll() {
1274                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1275            }
1276    
1277            /**
1278             * Returns a range of all the d l sync events.
1279             *
1280             * <p>
1281             * 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.
1282             * </p>
1283             *
1284             * @param start the lower bound of the range of d l sync events
1285             * @param end the upper bound of the range of d l sync events (not inclusive)
1286             * @return the range of d l sync events
1287             */
1288            @Override
1289            public List<DLSyncEvent> findAll(int start, int end) {
1290                    return findAll(start, end, null);
1291            }
1292    
1293            /**
1294             * Returns an ordered range of all the d l sync events.
1295             *
1296             * <p>
1297             * 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.
1298             * </p>
1299             *
1300             * @param start the lower bound of the range of d l sync events
1301             * @param end the upper bound of the range of d l sync events (not inclusive)
1302             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1303             * @return the ordered range of d l sync events
1304             */
1305            @Override
1306            public List<DLSyncEvent> findAll(int start, int end,
1307                    OrderByComparator<DLSyncEvent> orderByComparator) {
1308                    return findAll(start, end, orderByComparator, true);
1309            }
1310    
1311            /**
1312             * Returns an ordered range of all the d l sync events.
1313             *
1314             * <p>
1315             * 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.
1316             * </p>
1317             *
1318             * @param start the lower bound of the range of d l sync events
1319             * @param end the upper bound of the range of d l sync events (not inclusive)
1320             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1321             * @param retrieveFromCache whether to retrieve from the finder cache
1322             * @return the ordered range of d l sync events
1323             */
1324            @Override
1325            public List<DLSyncEvent> findAll(int start, int end,
1326                    OrderByComparator<DLSyncEvent> orderByComparator,
1327                    boolean retrieveFromCache) {
1328                    boolean pagination = true;
1329                    FinderPath finderPath = null;
1330                    Object[] finderArgs = null;
1331    
1332                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1333                                    (orderByComparator == null)) {
1334                            pagination = false;
1335                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1336                            finderArgs = FINDER_ARGS_EMPTY;
1337                    }
1338                    else {
1339                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1340                            finderArgs = new Object[] { start, end, orderByComparator };
1341                    }
1342    
1343                    List<DLSyncEvent> list = null;
1344    
1345                    if (retrieveFromCache) {
1346                            list = (List<DLSyncEvent>)finderCache.getResult(finderPath,
1347                                            finderArgs, this);
1348                    }
1349    
1350                    if (list == null) {
1351                            StringBundler query = null;
1352                            String sql = null;
1353    
1354                            if (orderByComparator != null) {
1355                                    query = new StringBundler(2 +
1356                                                    (orderByComparator.getOrderByFields().length * 2));
1357    
1358                                    query.append(_SQL_SELECT_DLSYNCEVENT);
1359    
1360                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1361                                            orderByComparator);
1362    
1363                                    sql = query.toString();
1364                            }
1365                            else {
1366                                    sql = _SQL_SELECT_DLSYNCEVENT;
1367    
1368                                    if (pagination) {
1369                                            sql = sql.concat(DLSyncEventModelImpl.ORDER_BY_JPQL);
1370                                    }
1371                            }
1372    
1373                            Session session = null;
1374    
1375                            try {
1376                                    session = openSession();
1377    
1378                                    Query q = session.createQuery(sql);
1379    
1380                                    if (!pagination) {
1381                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1382                                                            start, end, false);
1383    
1384                                            Collections.sort(list);
1385    
1386                                            list = Collections.unmodifiableList(list);
1387                                    }
1388                                    else {
1389                                            list = (List<DLSyncEvent>)QueryUtil.list(q, getDialect(),
1390                                                            start, end);
1391                                    }
1392    
1393                                    cacheResult(list);
1394    
1395                                    finderCache.putResult(finderPath, finderArgs, list);
1396                            }
1397                            catch (Exception e) {
1398                                    finderCache.removeResult(finderPath, finderArgs);
1399    
1400                                    throw processException(e);
1401                            }
1402                            finally {
1403                                    closeSession(session);
1404                            }
1405                    }
1406    
1407                    return list;
1408            }
1409    
1410            /**
1411             * Removes all the d l sync events from the database.
1412             *
1413             */
1414            @Override
1415            public void removeAll() {
1416                    for (DLSyncEvent dlSyncEvent : findAll()) {
1417                            remove(dlSyncEvent);
1418                    }
1419            }
1420    
1421            /**
1422             * Returns the number of d l sync events.
1423             *
1424             * @return the number of d l sync events
1425             */
1426            @Override
1427            public int countAll() {
1428                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1429                                    FINDER_ARGS_EMPTY, this);
1430    
1431                    if (count == null) {
1432                            Session session = null;
1433    
1434                            try {
1435                                    session = openSession();
1436    
1437                                    Query q = session.createQuery(_SQL_COUNT_DLSYNCEVENT);
1438    
1439                                    count = (Long)q.uniqueResult();
1440    
1441                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1442                                            count);
1443                            }
1444                            catch (Exception e) {
1445                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1446                                            FINDER_ARGS_EMPTY);
1447    
1448                                    throw processException(e);
1449                            }
1450                            finally {
1451                                    closeSession(session);
1452                            }
1453                    }
1454    
1455                    return count.intValue();
1456            }
1457    
1458            @Override
1459            public Set<String> getBadColumnNames() {
1460                    return _badColumnNames;
1461            }
1462    
1463            @Override
1464            protected Map<String, Integer> getTableColumnsMap() {
1465                    return DLSyncEventModelImpl.TABLE_COLUMNS_MAP;
1466            }
1467    
1468            /**
1469             * Initializes the d l sync event persistence.
1470             */
1471            public void afterPropertiesSet() {
1472            }
1473    
1474            public void destroy() {
1475                    entityCache.removeCache(DLSyncEventImpl.class.getName());
1476                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1477                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1478                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1479            }
1480    
1481            @BeanReference(type = CompanyProviderWrapper.class)
1482            protected CompanyProvider companyProvider;
1483            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1484            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1485            private static final String _SQL_SELECT_DLSYNCEVENT = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent";
1486            private static final String _SQL_SELECT_DLSYNCEVENT_WHERE_PKS_IN = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent WHERE syncEventId IN (";
1487            private static final String _SQL_SELECT_DLSYNCEVENT_WHERE = "SELECT dlSyncEvent FROM DLSyncEvent dlSyncEvent WHERE ";
1488            private static final String _SQL_COUNT_DLSYNCEVENT = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent";
1489            private static final String _SQL_COUNT_DLSYNCEVENT_WHERE = "SELECT COUNT(dlSyncEvent) FROM DLSyncEvent dlSyncEvent WHERE ";
1490            private static final String _ORDER_BY_ENTITY_ALIAS = "dlSyncEvent.";
1491            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSyncEvent exists with the primary key ";
1492            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSyncEvent exists with the key {";
1493            private static final Log _log = LogFactoryUtil.getLog(DLSyncEventPersistenceImpl.class);
1494            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1495                                    "type"
1496                            });
1497            private static final DLSyncEvent _nullDLSyncEvent = new DLSyncEventImpl() {
1498                            @Override
1499                            public Object clone() {
1500                                    return this;
1501                            }
1502    
1503                            @Override
1504                            public CacheModel<DLSyncEvent> toCacheModel() {
1505                                    return _nullDLSyncEventCacheModel;
1506                            }
1507                    };
1508    
1509            private static final CacheModel<DLSyncEvent> _nullDLSyncEventCacheModel = new CacheModel<DLSyncEvent>() {
1510                            @Override
1511                            public DLSyncEvent toEntityModel() {
1512                                    return _nullDLSyncEvent;
1513                            }
1514                    };
1515    }