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