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