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