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