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