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