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