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