001    /**
002     * Copyright (c) 2000-2013 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.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
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.NoSuchContentException;
045    import com.liferay.portlet.documentlibrary.model.DLContent;
046    import com.liferay.portlet.documentlibrary.model.impl.DLContentImpl;
047    import com.liferay.portlet.documentlibrary.model.impl.DLContentModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the document library content service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see DLContentPersistence
064     * @see DLContentUtil
065     * @generated
066     */
067    public class DLContentPersistenceImpl extends BasePersistenceImpl<DLContent>
068            implements DLContentPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link DLContentUtil} to access the document library content persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = DLContentImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
080                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R",
082                            new String[] {
083                                    Long.class.getName(), Long.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
089                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_R",
091                            new String[] { Long.class.getName(), Long.class.getName() },
092                            DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
093                            DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
095                            DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R",
097                            new String[] { Long.class.getName(), Long.class.getName() });
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
099                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R_P",
101                            new String[] {
102                                    Long.class.getName(), Long.class.getName(),
103                                    String.class.getName(),
104                                    
105                            "java.lang.Integer", "java.lang.Integer",
106                                    "com.liferay.portal.kernel.util.OrderByComparator"
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
109                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_R_P",
111                            new String[] {
112                                    Long.class.getName(), Long.class.getName(),
113                                    String.class.getName()
114                            },
115                            DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
116                            DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
117                            DLContentModelImpl.PATH_COLUMN_BITMASK);
118            public static final FinderPath FINDER_PATH_COUNT_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
119                            DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R_P",
121                            new String[] {
122                                    Long.class.getName(), Long.class.getName(),
123                                    String.class.getName()
124                            });
125            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_LIKEP =
126                    new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
127                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
128                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R_LikeP",
129                            new String[] {
130                                    Long.class.getName(), Long.class.getName(),
131                                    String.class.getName(),
132                                    
133                            "java.lang.Integer", "java.lang.Integer",
134                                    "com.liferay.portal.kernel.util.OrderByComparator"
135                            });
136            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP =
137                    new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
138                            DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
139                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_R_LikeP",
140                            new String[] {
141                                    Long.class.getName(), Long.class.getName(),
142                                    String.class.getName()
143                            });
144            public static final FinderPath FINDER_PATH_FETCH_BY_C_R_P_V = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
145                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
146                            FINDER_CLASS_NAME_ENTITY, "fetchByC_R_P_V",
147                            new String[] {
148                                    Long.class.getName(), Long.class.getName(),
149                                    String.class.getName(), String.class.getName()
150                            },
151                            DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
152                            DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
153                            DLContentModelImpl.PATH_COLUMN_BITMASK |
154                            DLContentModelImpl.VERSION_COLUMN_BITMASK);
155            public static final FinderPath FINDER_PATH_COUNT_BY_C_R_P_V = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
156                            DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
157                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R_P_V",
158                            new String[] {
159                                    Long.class.getName(), Long.class.getName(),
160                                    String.class.getName(), String.class.getName()
161                            });
162            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
163                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
164                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
165            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
166                            DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
168            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
169                            DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
170                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
171    
172            /**
173             * Caches the document library content in the entity cache if it is enabled.
174             *
175             * @param dlContent the document library content
176             */
177            public void cacheResult(DLContent dlContent) {
178                    EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
179                            DLContentImpl.class, dlContent.getPrimaryKey(), dlContent);
180    
181                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
182                            new Object[] {
183                                    Long.valueOf(dlContent.getCompanyId()),
184                                    Long.valueOf(dlContent.getRepositoryId()),
185                                    
186                            dlContent.getPath(),
187                                    
188                            dlContent.getVersion()
189                            }, dlContent);
190    
191                    dlContent.resetOriginalValues();
192            }
193    
194            /**
195             * Caches the document library contents in the entity cache if it is enabled.
196             *
197             * @param dlContents the document library contents
198             */
199            public void cacheResult(List<DLContent> dlContents) {
200                    for (DLContent dlContent : dlContents) {
201                            if (EntityCacheUtil.getResult(
202                                                    DLContentModelImpl.ENTITY_CACHE_ENABLED,
203                                                    DLContentImpl.class, dlContent.getPrimaryKey()) == null) {
204                                    cacheResult(dlContent);
205                            }
206                            else {
207                                    dlContent.resetOriginalValues();
208                            }
209                    }
210            }
211    
212            /**
213             * Clears the cache for all document library contents.
214             *
215             * <p>
216             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
217             * </p>
218             */
219            @Override
220            public void clearCache() {
221                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
222                            CacheRegistryUtil.clear(DLContentImpl.class.getName());
223                    }
224    
225                    EntityCacheUtil.clearCache(DLContentImpl.class.getName());
226    
227                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
228                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
229                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
230            }
231    
232            /**
233             * Clears the cache for the document library content.
234             *
235             * <p>
236             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
237             * </p>
238             */
239            @Override
240            public void clearCache(DLContent dlContent) {
241                    EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
242                            DLContentImpl.class, dlContent.getPrimaryKey());
243    
244                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
246    
247                    clearUniqueFindersCache(dlContent);
248            }
249    
250            @Override
251            public void clearCache(List<DLContent> dlContents) {
252                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
253                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
254    
255                    for (DLContent dlContent : dlContents) {
256                            EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
257                                    DLContentImpl.class, dlContent.getPrimaryKey());
258    
259                            clearUniqueFindersCache(dlContent);
260                    }
261            }
262    
263            protected void cacheUniqueFindersCache(DLContent dlContent) {
264                    if (dlContent.isNew()) {
265                            Object[] args = new Object[] {
266                                            Long.valueOf(dlContent.getCompanyId()),
267                                            Long.valueOf(dlContent.getRepositoryId()),
268                                            
269                                            dlContent.getPath(),
270                                            
271                                            dlContent.getVersion()
272                                    };
273    
274                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V, args,
275                                    Long.valueOf(1));
276                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V, args,
277                                    dlContent);
278                    }
279                    else {
280                            DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
281    
282                            if ((dlContentModelImpl.getColumnBitmask() &
283                                            FINDER_PATH_FETCH_BY_C_R_P_V.getColumnBitmask()) != 0) {
284                                    Object[] args = new Object[] {
285                                                    Long.valueOf(dlContent.getCompanyId()),
286                                                    Long.valueOf(dlContent.getRepositoryId()),
287                                                    
288                                                    dlContent.getPath(),
289                                                    
290                                                    dlContent.getVersion()
291                                            };
292    
293                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V, args,
294                                            Long.valueOf(1));
295                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V, args,
296                                            dlContent);
297                            }
298                    }
299            }
300    
301            protected void clearUniqueFindersCache(DLContent dlContent) {
302                    DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
303    
304                    Object[] args = new Object[] {
305                                    Long.valueOf(dlContent.getCompanyId()),
306                                    Long.valueOf(dlContent.getRepositoryId()),
307                                    
308                                    dlContent.getPath(),
309                                    
310                                    dlContent.getVersion()
311                            };
312    
313                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P_V, args);
314                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V, args);
315    
316                    if ((dlContentModelImpl.getColumnBitmask() &
317                                    FINDER_PATH_FETCH_BY_C_R_P_V.getColumnBitmask()) != 0) {
318                            args = new Object[] {
319                                            Long.valueOf(dlContentModelImpl.getOriginalCompanyId()),
320                                            Long.valueOf(dlContentModelImpl.getOriginalRepositoryId()),
321                                            
322                                            dlContentModelImpl.getOriginalPath(),
323                                            
324                                            dlContentModelImpl.getOriginalVersion()
325                                    };
326    
327                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P_V, args);
328                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V, args);
329                    }
330            }
331    
332            /**
333             * Creates a new document library content with the primary key. Does not add the document library content to the database.
334             *
335             * @param contentId the primary key for the new document library content
336             * @return the new document library content
337             */
338            public DLContent create(long contentId) {
339                    DLContent dlContent = new DLContentImpl();
340    
341                    dlContent.setNew(true);
342                    dlContent.setPrimaryKey(contentId);
343    
344                    return dlContent;
345            }
346    
347            /**
348             * Removes the document library content with the primary key from the database. Also notifies the appropriate model listeners.
349             *
350             * @param contentId the primary key of the document library content
351             * @return the document library content that was removed
352             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a document library content with the primary key could not be found
353             * @throws SystemException if a system exception occurred
354             */
355            public DLContent remove(long contentId)
356                    throws NoSuchContentException, SystemException {
357                    return remove(Long.valueOf(contentId));
358            }
359    
360            /**
361             * Removes the document library content with the primary key from the database. Also notifies the appropriate model listeners.
362             *
363             * @param primaryKey the primary key of the document library content
364             * @return the document library content that was removed
365             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a document library content with the primary key could not be found
366             * @throws SystemException if a system exception occurred
367             */
368            @Override
369            public DLContent remove(Serializable primaryKey)
370                    throws NoSuchContentException, SystemException {
371                    Session session = null;
372    
373                    try {
374                            session = openSession();
375    
376                            DLContent dlContent = (DLContent)session.get(DLContentImpl.class,
377                                            primaryKey);
378    
379                            if (dlContent == null) {
380                                    if (_log.isWarnEnabled()) {
381                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
382                                    }
383    
384                                    throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
385                                            primaryKey);
386                            }
387    
388                            return remove(dlContent);
389                    }
390                    catch (NoSuchContentException nsee) {
391                            throw nsee;
392                    }
393                    catch (Exception e) {
394                            throw processException(e);
395                    }
396                    finally {
397                            closeSession(session);
398                    }
399            }
400    
401            @Override
402            protected DLContent removeImpl(DLContent dlContent)
403                    throws SystemException {
404                    dlContent = toUnwrappedModel(dlContent);
405    
406                    Session session = null;
407    
408                    try {
409                            session = openSession();
410    
411                            BatchSessionUtil.delete(session, dlContent);
412                    }
413                    catch (Exception e) {
414                            throw processException(e);
415                    }
416                    finally {
417                            closeSession(session);
418                    }
419    
420                    clearCache(dlContent);
421    
422                    return dlContent;
423            }
424    
425            @Override
426            public DLContent updateImpl(
427                    com.liferay.portlet.documentlibrary.model.DLContent dlContent,
428                    boolean merge) throws SystemException {
429                    dlContent = toUnwrappedModel(dlContent);
430    
431                    boolean isNew = dlContent.isNew();
432    
433                    DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
434    
435                    Session session = null;
436    
437                    try {
438                            session = openSession();
439    
440                            BatchSessionUtil.update(session, dlContent, merge);
441    
442                            dlContent.setNew(false);
443    
444                            session.flush();
445                            session.clear();
446                    }
447                    catch (Exception e) {
448                            throw processException(e);
449                    }
450                    finally {
451                            closeSession(session);
452                    }
453    
454                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
455    
456                    if (isNew || !DLContentModelImpl.COLUMN_BITMASK_ENABLED) {
457                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
458                    }
459    
460                    else {
461                            if ((dlContentModelImpl.getColumnBitmask() &
462                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R.getColumnBitmask()) != 0) {
463                                    Object[] args = new Object[] {
464                                                    Long.valueOf(dlContentModelImpl.getOriginalCompanyId()),
465                                                    Long.valueOf(dlContentModelImpl.getOriginalRepositoryId())
466                                            };
467    
468                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
469                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R,
470                                            args);
471    
472                                    args = new Object[] {
473                                                    Long.valueOf(dlContentModelImpl.getCompanyId()),
474                                                    Long.valueOf(dlContentModelImpl.getRepositoryId())
475                                            };
476    
477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R,
479                                            args);
480                            }
481    
482                            if ((dlContentModelImpl.getColumnBitmask() &
483                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P.getColumnBitmask()) != 0) {
484                                    Object[] args = new Object[] {
485                                                    Long.valueOf(dlContentModelImpl.getOriginalCompanyId()),
486                                                    Long.valueOf(dlContentModelImpl.getOriginalRepositoryId()),
487                                                    
488                                                    dlContentModelImpl.getOriginalPath()
489                                            };
490    
491                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P, args);
492                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P,
493                                            args);
494    
495                                    args = new Object[] {
496                                                    Long.valueOf(dlContentModelImpl.getCompanyId()),
497                                                    Long.valueOf(dlContentModelImpl.getRepositoryId()),
498                                                    
499                                                    dlContentModelImpl.getPath()
500                                            };
501    
502                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P, args);
503                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P,
504                                            args);
505                            }
506                    }
507    
508                    EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
509                            DLContentImpl.class, dlContent.getPrimaryKey(), dlContent);
510    
511                    clearUniqueFindersCache(dlContent);
512                    cacheUniqueFindersCache(dlContent);
513    
514                    dlContent.resetOriginalValues();
515    
516                    return dlContent;
517            }
518    
519            protected DLContent toUnwrappedModel(DLContent dlContent) {
520                    if (dlContent instanceof DLContentImpl) {
521                            return dlContent;
522                    }
523    
524                    DLContentImpl dlContentImpl = new DLContentImpl();
525    
526                    dlContentImpl.setNew(dlContent.isNew());
527                    dlContentImpl.setPrimaryKey(dlContent.getPrimaryKey());
528    
529                    dlContentImpl.setContentId(dlContent.getContentId());
530                    dlContentImpl.setGroupId(dlContent.getGroupId());
531                    dlContentImpl.setCompanyId(dlContent.getCompanyId());
532                    dlContentImpl.setRepositoryId(dlContent.getRepositoryId());
533                    dlContentImpl.setPath(dlContent.getPath());
534                    dlContentImpl.setVersion(dlContent.getVersion());
535                    dlContentImpl.setData(dlContent.getData());
536                    dlContentImpl.setSize(dlContent.getSize());
537    
538                    return dlContentImpl;
539            }
540    
541            /**
542             * Returns the document library content with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
543             *
544             * @param primaryKey the primary key of the document library content
545             * @return the document library content
546             * @throws com.liferay.portal.NoSuchModelException if a document library content with the primary key could not be found
547             * @throws SystemException if a system exception occurred
548             */
549            @Override
550            public DLContent findByPrimaryKey(Serializable primaryKey)
551                    throws NoSuchModelException, SystemException {
552                    return findByPrimaryKey(((Long)primaryKey).longValue());
553            }
554    
555            /**
556             * Returns the document library content with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchContentException} if it could not be found.
557             *
558             * @param contentId the primary key of the document library content
559             * @return the document library content
560             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a document library content with the primary key could not be found
561             * @throws SystemException if a system exception occurred
562             */
563            public DLContent findByPrimaryKey(long contentId)
564                    throws NoSuchContentException, SystemException {
565                    DLContent dlContent = fetchByPrimaryKey(contentId);
566    
567                    if (dlContent == null) {
568                            if (_log.isWarnEnabled()) {
569                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
570                            }
571    
572                            throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
573                                    contentId);
574                    }
575    
576                    return dlContent;
577            }
578    
579            /**
580             * Returns the document library content with the primary key or returns <code>null</code> if it could not be found.
581             *
582             * @param primaryKey the primary key of the document library content
583             * @return the document library content, or <code>null</code> if a document library content with the primary key could not be found
584             * @throws SystemException if a system exception occurred
585             */
586            @Override
587            public DLContent fetchByPrimaryKey(Serializable primaryKey)
588                    throws SystemException {
589                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
590            }
591    
592            /**
593             * Returns the document library content with the primary key or returns <code>null</code> if it could not be found.
594             *
595             * @param contentId the primary key of the document library content
596             * @return the document library content, or <code>null</code> if a document library content with the primary key could not be found
597             * @throws SystemException if a system exception occurred
598             */
599            public DLContent fetchByPrimaryKey(long contentId)
600                    throws SystemException {
601                    DLContent dlContent = (DLContent)EntityCacheUtil.getResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
602                                    DLContentImpl.class, contentId);
603    
604                    if (dlContent == _nullDLContent) {
605                            return null;
606                    }
607    
608                    if (dlContent == null) {
609                            Session session = null;
610    
611                            boolean hasException = false;
612    
613                            try {
614                                    session = openSession();
615    
616                                    dlContent = (DLContent)session.get(DLContentImpl.class,
617                                                    Long.valueOf(contentId));
618                            }
619                            catch (Exception e) {
620                                    hasException = true;
621    
622                                    throw processException(e);
623                            }
624                            finally {
625                                    if (dlContent != null) {
626                                            cacheResult(dlContent);
627                                    }
628                                    else if (!hasException) {
629                                            EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
630                                                    DLContentImpl.class, contentId, _nullDLContent);
631                                    }
632    
633                                    closeSession(session);
634                            }
635                    }
636    
637                    return dlContent;
638            }
639    
640            /**
641             * Returns all the document library contents where companyId = &#63; and repositoryId = &#63;.
642             *
643             * @param companyId the company ID
644             * @param repositoryId the repository ID
645             * @return the matching document library contents
646             * @throws SystemException if a system exception occurred
647             */
648            public List<DLContent> findByC_R(long companyId, long repositoryId)
649                    throws SystemException {
650                    return findByC_R(companyId, repositoryId, QueryUtil.ALL_POS,
651                            QueryUtil.ALL_POS, null);
652            }
653    
654            /**
655             * Returns a range of all the document library contents where companyId = &#63; and repositoryId = &#63;.
656             *
657             * <p>
658             * 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.
659             * </p>
660             *
661             * @param companyId the company ID
662             * @param repositoryId the repository ID
663             * @param start the lower bound of the range of document library contents
664             * @param end the upper bound of the range of document library contents (not inclusive)
665             * @return the range of matching document library contents
666             * @throws SystemException if a system exception occurred
667             */
668            public List<DLContent> findByC_R(long companyId, long repositoryId,
669                    int start, int end) throws SystemException {
670                    return findByC_R(companyId, repositoryId, start, end, null);
671            }
672    
673            /**
674             * Returns an ordered range of all the document library contents where companyId = &#63; and repositoryId = &#63;.
675             *
676             * <p>
677             * 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.
678             * </p>
679             *
680             * @param companyId the company ID
681             * @param repositoryId the repository ID
682             * @param start the lower bound of the range of document library contents
683             * @param end the upper bound of the range of document library contents (not inclusive)
684             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
685             * @return the ordered range of matching document library contents
686             * @throws SystemException if a system exception occurred
687             */
688            public List<DLContent> findByC_R(long companyId, long repositoryId,
689                    int start, int end, OrderByComparator orderByComparator)
690                    throws SystemException {
691                    FinderPath finderPath = null;
692                    Object[] finderArgs = null;
693    
694                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
695                                    (orderByComparator == null)) {
696                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R;
697                            finderArgs = new Object[] { companyId, repositoryId };
698                    }
699                    else {
700                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R;
701                            finderArgs = new Object[] {
702                                            companyId, repositoryId,
703                                            
704                                            start, end, orderByComparator
705                                    };
706                    }
707    
708                    List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
709                                    finderArgs, this);
710    
711                    if ((list != null) && !list.isEmpty()) {
712                            for (DLContent dlContent : list) {
713                                    if ((companyId != dlContent.getCompanyId()) ||
714                                                    (repositoryId != dlContent.getRepositoryId())) {
715                                            list = null;
716    
717                                            break;
718                                    }
719                            }
720                    }
721    
722                    if (list == null) {
723                            StringBundler query = null;
724    
725                            if (orderByComparator != null) {
726                                    query = new StringBundler(4 +
727                                                    (orderByComparator.getOrderByFields().length * 3));
728                            }
729                            else {
730                                    query = new StringBundler(4);
731                            }
732    
733                            query.append(_SQL_SELECT_DLCONTENT_WHERE);
734    
735                            query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
736    
737                            query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
738    
739                            if (orderByComparator != null) {
740                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
741                                            orderByComparator);
742                            }
743    
744                            else {
745                                    query.append(DLContentModelImpl.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                                    qPos.add(repositoryId);
762    
763                                    list = (List<DLContent>)QueryUtil.list(q, getDialect(), start,
764                                                    end);
765                            }
766                            catch (Exception e) {
767                                    throw processException(e);
768                            }
769                            finally {
770                                    if (list == null) {
771                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
772                                    }
773                                    else {
774                                            cacheResult(list);
775    
776                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
777                                    }
778    
779                                    closeSession(session);
780                            }
781                    }
782    
783                    return list;
784            }
785    
786            /**
787             * Returns the first document library content in the ordered set where companyId = &#63; and repositoryId = &#63;.
788             *
789             * @param companyId the company ID
790             * @param repositoryId the repository ID
791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
792             * @return the first matching document library content
793             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
794             * @throws SystemException if a system exception occurred
795             */
796            public DLContent findByC_R_First(long companyId, long repositoryId,
797                    OrderByComparator orderByComparator)
798                    throws NoSuchContentException, SystemException {
799                    DLContent dlContent = fetchByC_R_First(companyId, repositoryId,
800                                    orderByComparator);
801    
802                    if (dlContent != null) {
803                            return dlContent;
804                    }
805    
806                    StringBundler msg = new StringBundler(6);
807    
808                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
809    
810                    msg.append("companyId=");
811                    msg.append(companyId);
812    
813                    msg.append(", repositoryId=");
814                    msg.append(repositoryId);
815    
816                    msg.append(StringPool.CLOSE_CURLY_BRACE);
817    
818                    throw new NoSuchContentException(msg.toString());
819            }
820    
821            /**
822             * Returns the first document library content in the ordered set where companyId = &#63; and repositoryId = &#63;.
823             *
824             * @param companyId the company ID
825             * @param repositoryId the repository ID
826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
827             * @return the first matching document library content, or <code>null</code> if a matching document library content could not be found
828             * @throws SystemException if a system exception occurred
829             */
830            public DLContent fetchByC_R_First(long companyId, long repositoryId,
831                    OrderByComparator orderByComparator) throws SystemException {
832                    List<DLContent> list = findByC_R(companyId, repositoryId, 0, 1,
833                                    orderByComparator);
834    
835                    if (!list.isEmpty()) {
836                            return list.get(0);
837                    }
838    
839                    return null;
840            }
841    
842            /**
843             * Returns the last document library content in the ordered set where companyId = &#63; and repositoryId = &#63;.
844             *
845             * @param companyId the company ID
846             * @param repositoryId the repository ID
847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
848             * @return the last matching document library content
849             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
850             * @throws SystemException if a system exception occurred
851             */
852            public DLContent findByC_R_Last(long companyId, long repositoryId,
853                    OrderByComparator orderByComparator)
854                    throws NoSuchContentException, SystemException {
855                    DLContent dlContent = fetchByC_R_Last(companyId, repositoryId,
856                                    orderByComparator);
857    
858                    if (dlContent != null) {
859                            return dlContent;
860                    }
861    
862                    StringBundler msg = new StringBundler(6);
863    
864                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
865    
866                    msg.append("companyId=");
867                    msg.append(companyId);
868    
869                    msg.append(", repositoryId=");
870                    msg.append(repositoryId);
871    
872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
873    
874                    throw new NoSuchContentException(msg.toString());
875            }
876    
877            /**
878             * Returns the last document library content in the ordered set where companyId = &#63; and repositoryId = &#63;.
879             *
880             * @param companyId the company ID
881             * @param repositoryId the repository ID
882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
883             * @return the last matching document library content, or <code>null</code> if a matching document library content could not be found
884             * @throws SystemException if a system exception occurred
885             */
886            public DLContent fetchByC_R_Last(long companyId, long repositoryId,
887                    OrderByComparator orderByComparator) throws SystemException {
888                    int count = countByC_R(companyId, repositoryId);
889    
890                    List<DLContent> list = findByC_R(companyId, repositoryId, count - 1,
891                                    count, orderByComparator);
892    
893                    if (!list.isEmpty()) {
894                            return list.get(0);
895                    }
896    
897                    return null;
898            }
899    
900            /**
901             * Returns the document library contents before and after the current document library content in the ordered set where companyId = &#63; and repositoryId = &#63;.
902             *
903             * @param contentId the primary key of the current document library content
904             * @param companyId the company ID
905             * @param repositoryId the repository ID
906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
907             * @return the previous, current, and next document library content
908             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a document library content with the primary key could not be found
909             * @throws SystemException if a system exception occurred
910             */
911            public DLContent[] findByC_R_PrevAndNext(long contentId, long companyId,
912                    long repositoryId, OrderByComparator orderByComparator)
913                    throws NoSuchContentException, SystemException {
914                    DLContent dlContent = findByPrimaryKey(contentId);
915    
916                    Session session = null;
917    
918                    try {
919                            session = openSession();
920    
921                            DLContent[] array = new DLContentImpl[3];
922    
923                            array[0] = getByC_R_PrevAndNext(session, dlContent, companyId,
924                                            repositoryId, orderByComparator, true);
925    
926                            array[1] = dlContent;
927    
928                            array[2] = getByC_R_PrevAndNext(session, dlContent, companyId,
929                                            repositoryId, orderByComparator, false);
930    
931                            return array;
932                    }
933                    catch (Exception e) {
934                            throw processException(e);
935                    }
936                    finally {
937                            closeSession(session);
938                    }
939            }
940    
941            protected DLContent getByC_R_PrevAndNext(Session session,
942                    DLContent dlContent, long companyId, long repositoryId,
943                    OrderByComparator orderByComparator, boolean previous) {
944                    StringBundler query = null;
945    
946                    if (orderByComparator != null) {
947                            query = new StringBundler(6 +
948                                            (orderByComparator.getOrderByFields().length * 6));
949                    }
950                    else {
951                            query = new StringBundler(3);
952                    }
953    
954                    query.append(_SQL_SELECT_DLCONTENT_WHERE);
955    
956                    query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
957    
958                    query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
959    
960                    if (orderByComparator != null) {
961                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
962    
963                            if (orderByConditionFields.length > 0) {
964                                    query.append(WHERE_AND);
965                            }
966    
967                            for (int i = 0; i < orderByConditionFields.length; i++) {
968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
969                                    query.append(orderByConditionFields[i]);
970    
971                                    if ((i + 1) < orderByConditionFields.length) {
972                                            if (orderByComparator.isAscending() ^ previous) {
973                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
974                                            }
975                                            else {
976                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
977                                            }
978                                    }
979                                    else {
980                                            if (orderByComparator.isAscending() ^ previous) {
981                                                    query.append(WHERE_GREATER_THAN);
982                                            }
983                                            else {
984                                                    query.append(WHERE_LESSER_THAN);
985                                            }
986                                    }
987                            }
988    
989                            query.append(ORDER_BY_CLAUSE);
990    
991                            String[] orderByFields = orderByComparator.getOrderByFields();
992    
993                            for (int i = 0; i < orderByFields.length; i++) {
994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
995                                    query.append(orderByFields[i]);
996    
997                                    if ((i + 1) < orderByFields.length) {
998                                            if (orderByComparator.isAscending() ^ previous) {
999                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1000                                            }
1001                                            else {
1002                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1003                                            }
1004                                    }
1005                                    else {
1006                                            if (orderByComparator.isAscending() ^ previous) {
1007                                                    query.append(ORDER_BY_ASC);
1008                                            }
1009                                            else {
1010                                                    query.append(ORDER_BY_DESC);
1011                                            }
1012                                    }
1013                            }
1014                    }
1015    
1016                    else {
1017                            query.append(DLContentModelImpl.ORDER_BY_JPQL);
1018                    }
1019    
1020                    String sql = query.toString();
1021    
1022                    Query q = session.createQuery(sql);
1023    
1024                    q.setFirstResult(0);
1025                    q.setMaxResults(2);
1026    
1027                    QueryPos qPos = QueryPos.getInstance(q);
1028    
1029                    qPos.add(companyId);
1030    
1031                    qPos.add(repositoryId);
1032    
1033                    if (orderByComparator != null) {
1034                            Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1035    
1036                            for (Object value : values) {
1037                                    qPos.add(value);
1038                            }
1039                    }
1040    
1041                    List<DLContent> list = q.list();
1042    
1043                    if (list.size() == 2) {
1044                            return list.get(1);
1045                    }
1046                    else {
1047                            return null;
1048                    }
1049            }
1050    
1051            /**
1052             * Returns all the document library contents where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1053             *
1054             * @param companyId the company ID
1055             * @param repositoryId the repository ID
1056             * @param path the path
1057             * @return the matching document library contents
1058             * @throws SystemException if a system exception occurred
1059             */
1060            public List<DLContent> findByC_R_P(long companyId, long repositoryId,
1061                    String path) throws SystemException {
1062                    return findByC_R_P(companyId, repositoryId, path, QueryUtil.ALL_POS,
1063                            QueryUtil.ALL_POS, null);
1064            }
1065    
1066            /**
1067             * Returns a range of all the document library contents where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1068             *
1069             * <p>
1070             * 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.
1071             * </p>
1072             *
1073             * @param companyId the company ID
1074             * @param repositoryId the repository ID
1075             * @param path the path
1076             * @param start the lower bound of the range of document library contents
1077             * @param end the upper bound of the range of document library contents (not inclusive)
1078             * @return the range of matching document library contents
1079             * @throws SystemException if a system exception occurred
1080             */
1081            public List<DLContent> findByC_R_P(long companyId, long repositoryId,
1082                    String path, int start, int end) throws SystemException {
1083                    return findByC_R_P(companyId, repositoryId, path, start, end, null);
1084            }
1085    
1086            /**
1087             * Returns an ordered range of all the document library contents where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1088             *
1089             * <p>
1090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1091             * </p>
1092             *
1093             * @param companyId the company ID
1094             * @param repositoryId the repository ID
1095             * @param path the path
1096             * @param start the lower bound of the range of document library contents
1097             * @param end the upper bound of the range of document library contents (not inclusive)
1098             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1099             * @return the ordered range of matching document library contents
1100             * @throws SystemException if a system exception occurred
1101             */
1102            public List<DLContent> findByC_R_P(long companyId, long repositoryId,
1103                    String path, int start, int end, OrderByComparator orderByComparator)
1104                    throws SystemException {
1105                    FinderPath finderPath = null;
1106                    Object[] finderArgs = null;
1107    
1108                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1109                                    (orderByComparator == null)) {
1110                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P;
1111                            finderArgs = new Object[] { companyId, repositoryId, path };
1112                    }
1113                    else {
1114                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_P;
1115                            finderArgs = new Object[] {
1116                                            companyId, repositoryId, path,
1117                                            
1118                                            start, end, orderByComparator
1119                                    };
1120                    }
1121    
1122                    List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
1123                                    finderArgs, this);
1124    
1125                    if ((list != null) && !list.isEmpty()) {
1126                            for (DLContent dlContent : list) {
1127                                    if ((companyId != dlContent.getCompanyId()) ||
1128                                                    (repositoryId != dlContent.getRepositoryId()) ||
1129                                                    !Validator.equals(path, dlContent.getPath())) {
1130                                            list = null;
1131    
1132                                            break;
1133                                    }
1134                            }
1135                    }
1136    
1137                    if (list == null) {
1138                            StringBundler query = null;
1139    
1140                            if (orderByComparator != null) {
1141                                    query = new StringBundler(5 +
1142                                                    (orderByComparator.getOrderByFields().length * 3));
1143                            }
1144                            else {
1145                                    query = new StringBundler(5);
1146                            }
1147    
1148                            query.append(_SQL_SELECT_DLCONTENT_WHERE);
1149    
1150                            query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
1151    
1152                            query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
1153    
1154                            if (path == null) {
1155                                    query.append(_FINDER_COLUMN_C_R_P_PATH_1);
1156                            }
1157                            else {
1158                                    if (path.equals(StringPool.BLANK)) {
1159                                            query.append(_FINDER_COLUMN_C_R_P_PATH_3);
1160                                    }
1161                                    else {
1162                                            query.append(_FINDER_COLUMN_C_R_P_PATH_2);
1163                                    }
1164                            }
1165    
1166                            if (orderByComparator != null) {
1167                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1168                                            orderByComparator);
1169                            }
1170    
1171                            else {
1172                                    query.append(DLContentModelImpl.ORDER_BY_JPQL);
1173                            }
1174    
1175                            String sql = query.toString();
1176    
1177                            Session session = null;
1178    
1179                            try {
1180                                    session = openSession();
1181    
1182                                    Query q = session.createQuery(sql);
1183    
1184                                    QueryPos qPos = QueryPos.getInstance(q);
1185    
1186                                    qPos.add(companyId);
1187    
1188                                    qPos.add(repositoryId);
1189    
1190                                    if (path != null) {
1191                                            qPos.add(path);
1192                                    }
1193    
1194                                    list = (List<DLContent>)QueryUtil.list(q, getDialect(), start,
1195                                                    end);
1196                            }
1197                            catch (Exception e) {
1198                                    throw processException(e);
1199                            }
1200                            finally {
1201                                    if (list == null) {
1202                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1203                                    }
1204                                    else {
1205                                            cacheResult(list);
1206    
1207                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1208                                    }
1209    
1210                                    closeSession(session);
1211                            }
1212                    }
1213    
1214                    return list;
1215            }
1216    
1217            /**
1218             * Returns the first document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1219             *
1220             * @param companyId the company ID
1221             * @param repositoryId the repository ID
1222             * @param path the path
1223             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1224             * @return the first matching document library content
1225             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
1226             * @throws SystemException if a system exception occurred
1227             */
1228            public DLContent findByC_R_P_First(long companyId, long repositoryId,
1229                    String path, OrderByComparator orderByComparator)
1230                    throws NoSuchContentException, SystemException {
1231                    DLContent dlContent = fetchByC_R_P_First(companyId, repositoryId, path,
1232                                    orderByComparator);
1233    
1234                    if (dlContent != null) {
1235                            return dlContent;
1236                    }
1237    
1238                    StringBundler msg = new StringBundler(8);
1239    
1240                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1241    
1242                    msg.append("companyId=");
1243                    msg.append(companyId);
1244    
1245                    msg.append(", repositoryId=");
1246                    msg.append(repositoryId);
1247    
1248                    msg.append(", path=");
1249                    msg.append(path);
1250    
1251                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1252    
1253                    throw new NoSuchContentException(msg.toString());
1254            }
1255    
1256            /**
1257             * Returns the first document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1258             *
1259             * @param companyId the company ID
1260             * @param repositoryId the repository ID
1261             * @param path the path
1262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1263             * @return the first matching document library content, or <code>null</code> if a matching document library content could not be found
1264             * @throws SystemException if a system exception occurred
1265             */
1266            public DLContent fetchByC_R_P_First(long companyId, long repositoryId,
1267                    String path, OrderByComparator orderByComparator)
1268                    throws SystemException {
1269                    List<DLContent> list = findByC_R_P(companyId, repositoryId, path, 0, 1,
1270                                    orderByComparator);
1271    
1272                    if (!list.isEmpty()) {
1273                            return list.get(0);
1274                    }
1275    
1276                    return null;
1277            }
1278    
1279            /**
1280             * Returns the last document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1281             *
1282             * @param companyId the company ID
1283             * @param repositoryId the repository ID
1284             * @param path the path
1285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1286             * @return the last matching document library content
1287             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
1288             * @throws SystemException if a system exception occurred
1289             */
1290            public DLContent findByC_R_P_Last(long companyId, long repositoryId,
1291                    String path, OrderByComparator orderByComparator)
1292                    throws NoSuchContentException, SystemException {
1293                    DLContent dlContent = fetchByC_R_P_Last(companyId, repositoryId, path,
1294                                    orderByComparator);
1295    
1296                    if (dlContent != null) {
1297                            return dlContent;
1298                    }
1299    
1300                    StringBundler msg = new StringBundler(8);
1301    
1302                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1303    
1304                    msg.append("companyId=");
1305                    msg.append(companyId);
1306    
1307                    msg.append(", repositoryId=");
1308                    msg.append(repositoryId);
1309    
1310                    msg.append(", path=");
1311                    msg.append(path);
1312    
1313                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1314    
1315                    throw new NoSuchContentException(msg.toString());
1316            }
1317    
1318            /**
1319             * Returns the last document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1320             *
1321             * @param companyId the company ID
1322             * @param repositoryId the repository ID
1323             * @param path the path
1324             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1325             * @return the last matching document library content, or <code>null</code> if a matching document library content could not be found
1326             * @throws SystemException if a system exception occurred
1327             */
1328            public DLContent fetchByC_R_P_Last(long companyId, long repositoryId,
1329                    String path, OrderByComparator orderByComparator)
1330                    throws SystemException {
1331                    int count = countByC_R_P(companyId, repositoryId, path);
1332    
1333                    List<DLContent> list = findByC_R_P(companyId, repositoryId, path,
1334                                    count - 1, count, orderByComparator);
1335    
1336                    if (!list.isEmpty()) {
1337                            return list.get(0);
1338                    }
1339    
1340                    return null;
1341            }
1342    
1343            /**
1344             * Returns the document library contents before and after the current document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path = &#63;.
1345             *
1346             * @param contentId the primary key of the current document library content
1347             * @param companyId the company ID
1348             * @param repositoryId the repository ID
1349             * @param path the path
1350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1351             * @return the previous, current, and next document library content
1352             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a document library content with the primary key could not be found
1353             * @throws SystemException if a system exception occurred
1354             */
1355            public DLContent[] findByC_R_P_PrevAndNext(long contentId, long companyId,
1356                    long repositoryId, String path, OrderByComparator orderByComparator)
1357                    throws NoSuchContentException, SystemException {
1358                    DLContent dlContent = findByPrimaryKey(contentId);
1359    
1360                    Session session = null;
1361    
1362                    try {
1363                            session = openSession();
1364    
1365                            DLContent[] array = new DLContentImpl[3];
1366    
1367                            array[0] = getByC_R_P_PrevAndNext(session, dlContent, companyId,
1368                                            repositoryId, path, orderByComparator, true);
1369    
1370                            array[1] = dlContent;
1371    
1372                            array[2] = getByC_R_P_PrevAndNext(session, dlContent, companyId,
1373                                            repositoryId, path, orderByComparator, false);
1374    
1375                            return array;
1376                    }
1377                    catch (Exception e) {
1378                            throw processException(e);
1379                    }
1380                    finally {
1381                            closeSession(session);
1382                    }
1383            }
1384    
1385            protected DLContent getByC_R_P_PrevAndNext(Session session,
1386                    DLContent dlContent, long companyId, long repositoryId, String path,
1387                    OrderByComparator orderByComparator, boolean previous) {
1388                    StringBundler query = null;
1389    
1390                    if (orderByComparator != null) {
1391                            query = new StringBundler(6 +
1392                                            (orderByComparator.getOrderByFields().length * 6));
1393                    }
1394                    else {
1395                            query = new StringBundler(3);
1396                    }
1397    
1398                    query.append(_SQL_SELECT_DLCONTENT_WHERE);
1399    
1400                    query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
1401    
1402                    query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
1403    
1404                    if (path == null) {
1405                            query.append(_FINDER_COLUMN_C_R_P_PATH_1);
1406                    }
1407                    else {
1408                            if (path.equals(StringPool.BLANK)) {
1409                                    query.append(_FINDER_COLUMN_C_R_P_PATH_3);
1410                            }
1411                            else {
1412                                    query.append(_FINDER_COLUMN_C_R_P_PATH_2);
1413                            }
1414                    }
1415    
1416                    if (orderByComparator != null) {
1417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1418    
1419                            if (orderByConditionFields.length > 0) {
1420                                    query.append(WHERE_AND);
1421                            }
1422    
1423                            for (int i = 0; i < orderByConditionFields.length; i++) {
1424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1425                                    query.append(orderByConditionFields[i]);
1426    
1427                                    if ((i + 1) < orderByConditionFields.length) {
1428                                            if (orderByComparator.isAscending() ^ previous) {
1429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1430                                            }
1431                                            else {
1432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1433                                            }
1434                                    }
1435                                    else {
1436                                            if (orderByComparator.isAscending() ^ previous) {
1437                                                    query.append(WHERE_GREATER_THAN);
1438                                            }
1439                                            else {
1440                                                    query.append(WHERE_LESSER_THAN);
1441                                            }
1442                                    }
1443                            }
1444    
1445                            query.append(ORDER_BY_CLAUSE);
1446    
1447                            String[] orderByFields = orderByComparator.getOrderByFields();
1448    
1449                            for (int i = 0; i < orderByFields.length; i++) {
1450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1451                                    query.append(orderByFields[i]);
1452    
1453                                    if ((i + 1) < orderByFields.length) {
1454                                            if (orderByComparator.isAscending() ^ previous) {
1455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1456                                            }
1457                                            else {
1458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1459                                            }
1460                                    }
1461                                    else {
1462                                            if (orderByComparator.isAscending() ^ previous) {
1463                                                    query.append(ORDER_BY_ASC);
1464                                            }
1465                                            else {
1466                                                    query.append(ORDER_BY_DESC);
1467                                            }
1468                                    }
1469                            }
1470                    }
1471    
1472                    else {
1473                            query.append(DLContentModelImpl.ORDER_BY_JPQL);
1474                    }
1475    
1476                    String sql = query.toString();
1477    
1478                    Query q = session.createQuery(sql);
1479    
1480                    q.setFirstResult(0);
1481                    q.setMaxResults(2);
1482    
1483                    QueryPos qPos = QueryPos.getInstance(q);
1484    
1485                    qPos.add(companyId);
1486    
1487                    qPos.add(repositoryId);
1488    
1489                    if (path != null) {
1490                            qPos.add(path);
1491                    }
1492    
1493                    if (orderByComparator != null) {
1494                            Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1495    
1496                            for (Object value : values) {
1497                                    qPos.add(value);
1498                            }
1499                    }
1500    
1501                    List<DLContent> list = q.list();
1502    
1503                    if (list.size() == 2) {
1504                            return list.get(1);
1505                    }
1506                    else {
1507                            return null;
1508                    }
1509            }
1510    
1511            /**
1512             * Returns all the document library contents where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1513             *
1514             * @param companyId the company ID
1515             * @param repositoryId the repository ID
1516             * @param path the path
1517             * @return the matching document library contents
1518             * @throws SystemException if a system exception occurred
1519             */
1520            public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1521                    String path) throws SystemException {
1522                    return findByC_R_LikeP(companyId, repositoryId, path,
1523                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1524            }
1525    
1526            /**
1527             * Returns a range of all the document library contents where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1528             *
1529             * <p>
1530             * 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.
1531             * </p>
1532             *
1533             * @param companyId the company ID
1534             * @param repositoryId the repository ID
1535             * @param path the path
1536             * @param start the lower bound of the range of document library contents
1537             * @param end the upper bound of the range of document library contents (not inclusive)
1538             * @return the range of matching document library contents
1539             * @throws SystemException if a system exception occurred
1540             */
1541            public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1542                    String path, int start, int end) throws SystemException {
1543                    return findByC_R_LikeP(companyId, repositoryId, path, start, end, null);
1544            }
1545    
1546            /**
1547             * Returns an ordered range of all the document library contents where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1548             *
1549             * <p>
1550             * 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.
1551             * </p>
1552             *
1553             * @param companyId the company ID
1554             * @param repositoryId the repository ID
1555             * @param path the path
1556             * @param start the lower bound of the range of document library contents
1557             * @param end the upper bound of the range of document library contents (not inclusive)
1558             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1559             * @return the ordered range of matching document library contents
1560             * @throws SystemException if a system exception occurred
1561             */
1562            public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1563                    String path, int start, int end, OrderByComparator orderByComparator)
1564                    throws SystemException {
1565                    FinderPath finderPath = null;
1566                    Object[] finderArgs = null;
1567    
1568                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_LIKEP;
1569                    finderArgs = new Object[] {
1570                                    companyId, repositoryId, path,
1571                                    
1572                                    start, end, orderByComparator
1573                            };
1574    
1575                    List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
1576                                    finderArgs, this);
1577    
1578                    if ((list != null) && !list.isEmpty()) {
1579                            for (DLContent dlContent : list) {
1580                                    if ((companyId != dlContent.getCompanyId()) ||
1581                                                    (repositoryId != dlContent.getRepositoryId()) ||
1582                                                    !Validator.equals(path, dlContent.getPath())) {
1583                                            list = null;
1584    
1585                                            break;
1586                                    }
1587                            }
1588                    }
1589    
1590                    if (list == null) {
1591                            StringBundler query = null;
1592    
1593                            if (orderByComparator != null) {
1594                                    query = new StringBundler(5 +
1595                                                    (orderByComparator.getOrderByFields().length * 3));
1596                            }
1597                            else {
1598                                    query = new StringBundler(5);
1599                            }
1600    
1601                            query.append(_SQL_SELECT_DLCONTENT_WHERE);
1602    
1603                            query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1604    
1605                            query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1606    
1607                            if (path == null) {
1608                                    query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1609                            }
1610                            else {
1611                                    if (path.equals(StringPool.BLANK)) {
1612                                            query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1613                                    }
1614                                    else {
1615                                            query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1616                                    }
1617                            }
1618    
1619                            if (orderByComparator != null) {
1620                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1621                                            orderByComparator);
1622                            }
1623    
1624                            else {
1625                                    query.append(DLContentModelImpl.ORDER_BY_JPQL);
1626                            }
1627    
1628                            String sql = query.toString();
1629    
1630                            Session session = null;
1631    
1632                            try {
1633                                    session = openSession();
1634    
1635                                    Query q = session.createQuery(sql);
1636    
1637                                    QueryPos qPos = QueryPos.getInstance(q);
1638    
1639                                    qPos.add(companyId);
1640    
1641                                    qPos.add(repositoryId);
1642    
1643                                    if (path != null) {
1644                                            qPos.add(path);
1645                                    }
1646    
1647                                    list = (List<DLContent>)QueryUtil.list(q, getDialect(), start,
1648                                                    end);
1649                            }
1650                            catch (Exception e) {
1651                                    throw processException(e);
1652                            }
1653                            finally {
1654                                    if (list == null) {
1655                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1656                                    }
1657                                    else {
1658                                            cacheResult(list);
1659    
1660                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1661                                    }
1662    
1663                                    closeSession(session);
1664                            }
1665                    }
1666    
1667                    return list;
1668            }
1669    
1670            /**
1671             * Returns the first document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1672             *
1673             * @param companyId the company ID
1674             * @param repositoryId the repository ID
1675             * @param path the path
1676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1677             * @return the first matching document library content
1678             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
1679             * @throws SystemException if a system exception occurred
1680             */
1681            public DLContent findByC_R_LikeP_First(long companyId, long repositoryId,
1682                    String path, OrderByComparator orderByComparator)
1683                    throws NoSuchContentException, SystemException {
1684                    DLContent dlContent = fetchByC_R_LikeP_First(companyId, repositoryId,
1685                                    path, orderByComparator);
1686    
1687                    if (dlContent != null) {
1688                            return dlContent;
1689                    }
1690    
1691                    StringBundler msg = new StringBundler(8);
1692    
1693                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1694    
1695                    msg.append("companyId=");
1696                    msg.append(companyId);
1697    
1698                    msg.append(", repositoryId=");
1699                    msg.append(repositoryId);
1700    
1701                    msg.append(", path=");
1702                    msg.append(path);
1703    
1704                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1705    
1706                    throw new NoSuchContentException(msg.toString());
1707            }
1708    
1709            /**
1710             * Returns the first document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1711             *
1712             * @param companyId the company ID
1713             * @param repositoryId the repository ID
1714             * @param path the path
1715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1716             * @return the first matching document library content, or <code>null</code> if a matching document library content could not be found
1717             * @throws SystemException if a system exception occurred
1718             */
1719            public DLContent fetchByC_R_LikeP_First(long companyId, long repositoryId,
1720                    String path, OrderByComparator orderByComparator)
1721                    throws SystemException {
1722                    List<DLContent> list = findByC_R_LikeP(companyId, repositoryId, path,
1723                                    0, 1, orderByComparator);
1724    
1725                    if (!list.isEmpty()) {
1726                            return list.get(0);
1727                    }
1728    
1729                    return null;
1730            }
1731    
1732            /**
1733             * Returns the last document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1734             *
1735             * @param companyId the company ID
1736             * @param repositoryId the repository ID
1737             * @param path the path
1738             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1739             * @return the last matching document library content
1740             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
1741             * @throws SystemException if a system exception occurred
1742             */
1743            public DLContent findByC_R_LikeP_Last(long companyId, long repositoryId,
1744                    String path, OrderByComparator orderByComparator)
1745                    throws NoSuchContentException, SystemException {
1746                    DLContent dlContent = fetchByC_R_LikeP_Last(companyId, repositoryId,
1747                                    path, orderByComparator);
1748    
1749                    if (dlContent != null) {
1750                            return dlContent;
1751                    }
1752    
1753                    StringBundler msg = new StringBundler(8);
1754    
1755                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1756    
1757                    msg.append("companyId=");
1758                    msg.append(companyId);
1759    
1760                    msg.append(", repositoryId=");
1761                    msg.append(repositoryId);
1762    
1763                    msg.append(", path=");
1764                    msg.append(path);
1765    
1766                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1767    
1768                    throw new NoSuchContentException(msg.toString());
1769            }
1770    
1771            /**
1772             * Returns the last document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1773             *
1774             * @param companyId the company ID
1775             * @param repositoryId the repository ID
1776             * @param path the path
1777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1778             * @return the last matching document library content, or <code>null</code> if a matching document library content could not be found
1779             * @throws SystemException if a system exception occurred
1780             */
1781            public DLContent fetchByC_R_LikeP_Last(long companyId, long repositoryId,
1782                    String path, OrderByComparator orderByComparator)
1783                    throws SystemException {
1784                    int count = countByC_R_LikeP(companyId, repositoryId, path);
1785    
1786                    List<DLContent> list = findByC_R_LikeP(companyId, repositoryId, path,
1787                                    count - 1, count, orderByComparator);
1788    
1789                    if (!list.isEmpty()) {
1790                            return list.get(0);
1791                    }
1792    
1793                    return null;
1794            }
1795    
1796            /**
1797             * Returns the document library contents before and after the current document library content in the ordered set where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
1798             *
1799             * @param contentId the primary key of the current document library content
1800             * @param companyId the company ID
1801             * @param repositoryId the repository ID
1802             * @param path the path
1803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1804             * @return the previous, current, and next document library content
1805             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a document library content with the primary key could not be found
1806             * @throws SystemException if a system exception occurred
1807             */
1808            public DLContent[] findByC_R_LikeP_PrevAndNext(long contentId,
1809                    long companyId, long repositoryId, String path,
1810                    OrderByComparator orderByComparator)
1811                    throws NoSuchContentException, SystemException {
1812                    DLContent dlContent = findByPrimaryKey(contentId);
1813    
1814                    Session session = null;
1815    
1816                    try {
1817                            session = openSession();
1818    
1819                            DLContent[] array = new DLContentImpl[3];
1820    
1821                            array[0] = getByC_R_LikeP_PrevAndNext(session, dlContent,
1822                                            companyId, repositoryId, path, orderByComparator, true);
1823    
1824                            array[1] = dlContent;
1825    
1826                            array[2] = getByC_R_LikeP_PrevAndNext(session, dlContent,
1827                                            companyId, repositoryId, path, orderByComparator, false);
1828    
1829                            return array;
1830                    }
1831                    catch (Exception e) {
1832                            throw processException(e);
1833                    }
1834                    finally {
1835                            closeSession(session);
1836                    }
1837            }
1838    
1839            protected DLContent getByC_R_LikeP_PrevAndNext(Session session,
1840                    DLContent dlContent, long companyId, long repositoryId, String path,
1841                    OrderByComparator orderByComparator, boolean previous) {
1842                    StringBundler query = null;
1843    
1844                    if (orderByComparator != null) {
1845                            query = new StringBundler(6 +
1846                                            (orderByComparator.getOrderByFields().length * 6));
1847                    }
1848                    else {
1849                            query = new StringBundler(3);
1850                    }
1851    
1852                    query.append(_SQL_SELECT_DLCONTENT_WHERE);
1853    
1854                    query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1855    
1856                    query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1857    
1858                    if (path == null) {
1859                            query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1860                    }
1861                    else {
1862                            if (path.equals(StringPool.BLANK)) {
1863                                    query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1864                            }
1865                            else {
1866                                    query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1867                            }
1868                    }
1869    
1870                    if (orderByComparator != null) {
1871                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1872    
1873                            if (orderByConditionFields.length > 0) {
1874                                    query.append(WHERE_AND);
1875                            }
1876    
1877                            for (int i = 0; i < orderByConditionFields.length; i++) {
1878                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1879                                    query.append(orderByConditionFields[i]);
1880    
1881                                    if ((i + 1) < orderByConditionFields.length) {
1882                                            if (orderByComparator.isAscending() ^ previous) {
1883                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1884                                            }
1885                                            else {
1886                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1887                                            }
1888                                    }
1889                                    else {
1890                                            if (orderByComparator.isAscending() ^ previous) {
1891                                                    query.append(WHERE_GREATER_THAN);
1892                                            }
1893                                            else {
1894                                                    query.append(WHERE_LESSER_THAN);
1895                                            }
1896                                    }
1897                            }
1898    
1899                            query.append(ORDER_BY_CLAUSE);
1900    
1901                            String[] orderByFields = orderByComparator.getOrderByFields();
1902    
1903                            for (int i = 0; i < orderByFields.length; i++) {
1904                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1905                                    query.append(orderByFields[i]);
1906    
1907                                    if ((i + 1) < orderByFields.length) {
1908                                            if (orderByComparator.isAscending() ^ previous) {
1909                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1910                                            }
1911                                            else {
1912                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1913                                            }
1914                                    }
1915                                    else {
1916                                            if (orderByComparator.isAscending() ^ previous) {
1917                                                    query.append(ORDER_BY_ASC);
1918                                            }
1919                                            else {
1920                                                    query.append(ORDER_BY_DESC);
1921                                            }
1922                                    }
1923                            }
1924                    }
1925    
1926                    else {
1927                            query.append(DLContentModelImpl.ORDER_BY_JPQL);
1928                    }
1929    
1930                    String sql = query.toString();
1931    
1932                    Query q = session.createQuery(sql);
1933    
1934                    q.setFirstResult(0);
1935                    q.setMaxResults(2);
1936    
1937                    QueryPos qPos = QueryPos.getInstance(q);
1938    
1939                    qPos.add(companyId);
1940    
1941                    qPos.add(repositoryId);
1942    
1943                    if (path != null) {
1944                            qPos.add(path);
1945                    }
1946    
1947                    if (orderByComparator != null) {
1948                            Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1949    
1950                            for (Object value : values) {
1951                                    qPos.add(value);
1952                            }
1953                    }
1954    
1955                    List<DLContent> list = q.list();
1956    
1957                    if (list.size() == 2) {
1958                            return list.get(1);
1959                    }
1960                    else {
1961                            return null;
1962                    }
1963            }
1964    
1965            /**
1966             * Returns the document library content where companyId = &#63; and repositoryId = &#63; and path = &#63; and version = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchContentException} if it could not be found.
1967             *
1968             * @param companyId the company ID
1969             * @param repositoryId the repository ID
1970             * @param path the path
1971             * @param version the version
1972             * @return the matching document library content
1973             * @throws com.liferay.portlet.documentlibrary.NoSuchContentException if a matching document library content could not be found
1974             * @throws SystemException if a system exception occurred
1975             */
1976            public DLContent findByC_R_P_V(long companyId, long repositoryId,
1977                    String path, String version)
1978                    throws NoSuchContentException, SystemException {
1979                    DLContent dlContent = fetchByC_R_P_V(companyId, repositoryId, path,
1980                                    version);
1981    
1982                    if (dlContent == null) {
1983                            StringBundler msg = new StringBundler(10);
1984    
1985                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1986    
1987                            msg.append("companyId=");
1988                            msg.append(companyId);
1989    
1990                            msg.append(", repositoryId=");
1991                            msg.append(repositoryId);
1992    
1993                            msg.append(", path=");
1994                            msg.append(path);
1995    
1996                            msg.append(", version=");
1997                            msg.append(version);
1998    
1999                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2000    
2001                            if (_log.isWarnEnabled()) {
2002                                    _log.warn(msg.toString());
2003                            }
2004    
2005                            throw new NoSuchContentException(msg.toString());
2006                    }
2007    
2008                    return dlContent;
2009            }
2010    
2011            /**
2012             * Returns the document library content where companyId = &#63; and repositoryId = &#63; and path = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2013             *
2014             * @param companyId the company ID
2015             * @param repositoryId the repository ID
2016             * @param path the path
2017             * @param version the version
2018             * @return the matching document library content, or <code>null</code> if a matching document library content could not be found
2019             * @throws SystemException if a system exception occurred
2020             */
2021            public DLContent fetchByC_R_P_V(long companyId, long repositoryId,
2022                    String path, String version) throws SystemException {
2023                    return fetchByC_R_P_V(companyId, repositoryId, path, version, true);
2024            }
2025    
2026            /**
2027             * Returns the document library content where companyId = &#63; and repositoryId = &#63; and path = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2028             *
2029             * @param companyId the company ID
2030             * @param repositoryId the repository ID
2031             * @param path the path
2032             * @param version the version
2033             * @param retrieveFromCache whether to use the finder cache
2034             * @return the matching document library content, or <code>null</code> if a matching document library content could not be found
2035             * @throws SystemException if a system exception occurred
2036             */
2037            public DLContent fetchByC_R_P_V(long companyId, long repositoryId,
2038                    String path, String version, boolean retrieveFromCache)
2039                    throws SystemException {
2040                    Object[] finderArgs = new Object[] {
2041                                    companyId, repositoryId, path, version
2042                            };
2043    
2044                    Object result = null;
2045    
2046                    if (retrieveFromCache) {
2047                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R_P_V,
2048                                            finderArgs, this);
2049                    }
2050    
2051                    if (result instanceof DLContent) {
2052                            DLContent dlContent = (DLContent)result;
2053    
2054                            if ((companyId != dlContent.getCompanyId()) ||
2055                                            (repositoryId != dlContent.getRepositoryId()) ||
2056                                            !Validator.equals(path, dlContent.getPath()) ||
2057                                            !Validator.equals(version, dlContent.getVersion())) {
2058                                    result = null;
2059                            }
2060                    }
2061    
2062                    if (result == null) {
2063                            StringBundler query = new StringBundler(6);
2064    
2065                            query.append(_SQL_SELECT_DLCONTENT_WHERE);
2066    
2067                            query.append(_FINDER_COLUMN_C_R_P_V_COMPANYID_2);
2068    
2069                            query.append(_FINDER_COLUMN_C_R_P_V_REPOSITORYID_2);
2070    
2071                            if (path == null) {
2072                                    query.append(_FINDER_COLUMN_C_R_P_V_PATH_1);
2073                            }
2074                            else {
2075                                    if (path.equals(StringPool.BLANK)) {
2076                                            query.append(_FINDER_COLUMN_C_R_P_V_PATH_3);
2077                                    }
2078                                    else {
2079                                            query.append(_FINDER_COLUMN_C_R_P_V_PATH_2);
2080                                    }
2081                            }
2082    
2083                            if (version == null) {
2084                                    query.append(_FINDER_COLUMN_C_R_P_V_VERSION_1);
2085                            }
2086                            else {
2087                                    if (version.equals(StringPool.BLANK)) {
2088                                            query.append(_FINDER_COLUMN_C_R_P_V_VERSION_3);
2089                                    }
2090                                    else {
2091                                            query.append(_FINDER_COLUMN_C_R_P_V_VERSION_2);
2092                                    }
2093                            }
2094    
2095                            query.append(DLContentModelImpl.ORDER_BY_JPQL);
2096    
2097                            String sql = query.toString();
2098    
2099                            Session session = null;
2100    
2101                            try {
2102                                    session = openSession();
2103    
2104                                    Query q = session.createQuery(sql);
2105    
2106                                    QueryPos qPos = QueryPos.getInstance(q);
2107    
2108                                    qPos.add(companyId);
2109    
2110                                    qPos.add(repositoryId);
2111    
2112                                    if (path != null) {
2113                                            qPos.add(path);
2114                                    }
2115    
2116                                    if (version != null) {
2117                                            qPos.add(version);
2118                                    }
2119    
2120                                    List<DLContent> list = q.list();
2121    
2122                                    result = list;
2123    
2124                                    DLContent dlContent = null;
2125    
2126                                    if (list.isEmpty()) {
2127                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
2128                                                    finderArgs, list);
2129                                    }
2130                                    else {
2131                                            dlContent = list.get(0);
2132    
2133                                            cacheResult(dlContent);
2134    
2135                                            if ((dlContent.getCompanyId() != companyId) ||
2136                                                            (dlContent.getRepositoryId() != repositoryId) ||
2137                                                            (dlContent.getPath() == null) ||
2138                                                            !dlContent.getPath().equals(path) ||
2139                                                            (dlContent.getVersion() == null) ||
2140                                                            !dlContent.getVersion().equals(version)) {
2141                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
2142                                                            finderArgs, dlContent);
2143                                            }
2144                                    }
2145    
2146                                    return dlContent;
2147                            }
2148                            catch (Exception e) {
2149                                    throw processException(e);
2150                            }
2151                            finally {
2152                                    if (result == null) {
2153                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V,
2154                                                    finderArgs);
2155                                    }
2156    
2157                                    closeSession(session);
2158                            }
2159                    }
2160                    else {
2161                            if (result instanceof List<?>) {
2162                                    return null;
2163                            }
2164                            else {
2165                                    return (DLContent)result;
2166                            }
2167                    }
2168            }
2169    
2170            /**
2171             * Returns all the document library contents.
2172             *
2173             * @return the document library contents
2174             * @throws SystemException if a system exception occurred
2175             */
2176            public List<DLContent> findAll() throws SystemException {
2177                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2178            }
2179    
2180            /**
2181             * Returns a range of all the document library contents.
2182             *
2183             * <p>
2184             * 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.
2185             * </p>
2186             *
2187             * @param start the lower bound of the range of document library contents
2188             * @param end the upper bound of the range of document library contents (not inclusive)
2189             * @return the range of document library contents
2190             * @throws SystemException if a system exception occurred
2191             */
2192            public List<DLContent> findAll(int start, int end)
2193                    throws SystemException {
2194                    return findAll(start, end, null);
2195            }
2196    
2197            /**
2198             * Returns an ordered range of all the document library contents.
2199             *
2200             * <p>
2201             * 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.
2202             * </p>
2203             *
2204             * @param start the lower bound of the range of document library contents
2205             * @param end the upper bound of the range of document library contents (not inclusive)
2206             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2207             * @return the ordered range of document library contents
2208             * @throws SystemException if a system exception occurred
2209             */
2210            public List<DLContent> findAll(int start, int end,
2211                    OrderByComparator orderByComparator) throws SystemException {
2212                    FinderPath finderPath = null;
2213                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2214    
2215                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2216                                    (orderByComparator == null)) {
2217                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2218                            finderArgs = FINDER_ARGS_EMPTY;
2219                    }
2220                    else {
2221                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2222                            finderArgs = new Object[] { start, end, orderByComparator };
2223                    }
2224    
2225                    List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
2226                                    finderArgs, this);
2227    
2228                    if (list == null) {
2229                            StringBundler query = null;
2230                            String sql = null;
2231    
2232                            if (orderByComparator != null) {
2233                                    query = new StringBundler(2 +
2234                                                    (orderByComparator.getOrderByFields().length * 3));
2235    
2236                                    query.append(_SQL_SELECT_DLCONTENT);
2237    
2238                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2239                                            orderByComparator);
2240    
2241                                    sql = query.toString();
2242                            }
2243                            else {
2244                                    sql = _SQL_SELECT_DLCONTENT.concat(DLContentModelImpl.ORDER_BY_JPQL);
2245                            }
2246    
2247                            Session session = null;
2248    
2249                            try {
2250                                    session = openSession();
2251    
2252                                    Query q = session.createQuery(sql);
2253    
2254                                    if (orderByComparator == null) {
2255                                            list = (List<DLContent>)QueryUtil.list(q, getDialect(),
2256                                                            start, end, false);
2257    
2258                                            Collections.sort(list);
2259                                    }
2260                                    else {
2261                                            list = (List<DLContent>)QueryUtil.list(q, getDialect(),
2262                                                            start, end);
2263                                    }
2264                            }
2265                            catch (Exception e) {
2266                                    throw processException(e);
2267                            }
2268                            finally {
2269                                    if (list == null) {
2270                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2271                                    }
2272                                    else {
2273                                            cacheResult(list);
2274    
2275                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2276                                    }
2277    
2278                                    closeSession(session);
2279                            }
2280                    }
2281    
2282                    return list;
2283            }
2284    
2285            /**
2286             * Removes all the document library contents where companyId = &#63; and repositoryId = &#63; from the database.
2287             *
2288             * @param companyId the company ID
2289             * @param repositoryId the repository ID
2290             * @throws SystemException if a system exception occurred
2291             */
2292            public void removeByC_R(long companyId, long repositoryId)
2293                    throws SystemException {
2294                    for (DLContent dlContent : findByC_R(companyId, repositoryId)) {
2295                            remove(dlContent);
2296                    }
2297            }
2298    
2299            /**
2300             * Removes all the document library contents where companyId = &#63; and repositoryId = &#63; and path = &#63; from the database.
2301             *
2302             * @param companyId the company ID
2303             * @param repositoryId the repository ID
2304             * @param path the path
2305             * @throws SystemException if a system exception occurred
2306             */
2307            public void removeByC_R_P(long companyId, long repositoryId, String path)
2308                    throws SystemException {
2309                    for (DLContent dlContent : findByC_R_P(companyId, repositoryId, path)) {
2310                            remove(dlContent);
2311                    }
2312            }
2313    
2314            /**
2315             * Removes all the document library contents where companyId = &#63; and repositoryId = &#63; and path LIKE &#63; from the database.
2316             *
2317             * @param companyId the company ID
2318             * @param repositoryId the repository ID
2319             * @param path the path
2320             * @throws SystemException if a system exception occurred
2321             */
2322            public void removeByC_R_LikeP(long companyId, long repositoryId, String path)
2323                    throws SystemException {
2324                    for (DLContent dlContent : findByC_R_LikeP(companyId, repositoryId, path)) {
2325                            remove(dlContent);
2326                    }
2327            }
2328    
2329            /**
2330             * Removes the document library content where companyId = &#63; and repositoryId = &#63; and path = &#63; and version = &#63; from the database.
2331             *
2332             * @param companyId the company ID
2333             * @param repositoryId the repository ID
2334             * @param path the path
2335             * @param version the version
2336             * @return the document library content that was removed
2337             * @throws SystemException if a system exception occurred
2338             */
2339            public DLContent removeByC_R_P_V(long companyId, long repositoryId,
2340                    String path, String version)
2341                    throws NoSuchContentException, SystemException {
2342                    DLContent dlContent = findByC_R_P_V(companyId, repositoryId, path,
2343                                    version);
2344    
2345                    return remove(dlContent);
2346            }
2347    
2348            /**
2349             * Removes all the document library contents from the database.
2350             *
2351             * @throws SystemException if a system exception occurred
2352             */
2353            public void removeAll() throws SystemException {
2354                    for (DLContent dlContent : findAll()) {
2355                            remove(dlContent);
2356                    }
2357            }
2358    
2359            /**
2360             * Returns the number of document library contents where companyId = &#63; and repositoryId = &#63;.
2361             *
2362             * @param companyId the company ID
2363             * @param repositoryId the repository ID
2364             * @return the number of matching document library contents
2365             * @throws SystemException if a system exception occurred
2366             */
2367            public int countByC_R(long companyId, long repositoryId)
2368                    throws SystemException {
2369                    Object[] finderArgs = new Object[] { companyId, repositoryId };
2370    
2371                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_R,
2372                                    finderArgs, this);
2373    
2374                    if (count == null) {
2375                            StringBundler query = new StringBundler(3);
2376    
2377                            query.append(_SQL_COUNT_DLCONTENT_WHERE);
2378    
2379                            query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
2380    
2381                            query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
2382    
2383                            String sql = query.toString();
2384    
2385                            Session session = null;
2386    
2387                            try {
2388                                    session = openSession();
2389    
2390                                    Query q = session.createQuery(sql);
2391    
2392                                    QueryPos qPos = QueryPos.getInstance(q);
2393    
2394                                    qPos.add(companyId);
2395    
2396                                    qPos.add(repositoryId);
2397    
2398                                    count = (Long)q.uniqueResult();
2399                            }
2400                            catch (Exception e) {
2401                                    throw processException(e);
2402                            }
2403                            finally {
2404                                    if (count == null) {
2405                                            count = Long.valueOf(0);
2406                                    }
2407    
2408                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R, finderArgs,
2409                                            count);
2410    
2411                                    closeSession(session);
2412                            }
2413                    }
2414    
2415                    return count.intValue();
2416            }
2417    
2418            /**
2419             * Returns the number of document library contents where companyId = &#63; and repositoryId = &#63; and path = &#63;.
2420             *
2421             * @param companyId the company ID
2422             * @param repositoryId the repository ID
2423             * @param path the path
2424             * @return the number of matching document library contents
2425             * @throws SystemException if a system exception occurred
2426             */
2427            public int countByC_R_P(long companyId, long repositoryId, String path)
2428                    throws SystemException {
2429                    Object[] finderArgs = new Object[] { companyId, repositoryId, path };
2430    
2431                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_R_P,
2432                                    finderArgs, this);
2433    
2434                    if (count == null) {
2435                            StringBundler query = new StringBundler(4);
2436    
2437                            query.append(_SQL_COUNT_DLCONTENT_WHERE);
2438    
2439                            query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
2440    
2441                            query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
2442    
2443                            if (path == null) {
2444                                    query.append(_FINDER_COLUMN_C_R_P_PATH_1);
2445                            }
2446                            else {
2447                                    if (path.equals(StringPool.BLANK)) {
2448                                            query.append(_FINDER_COLUMN_C_R_P_PATH_3);
2449                                    }
2450                                    else {
2451                                            query.append(_FINDER_COLUMN_C_R_P_PATH_2);
2452                                    }
2453                            }
2454    
2455                            String sql = query.toString();
2456    
2457                            Session session = null;
2458    
2459                            try {
2460                                    session = openSession();
2461    
2462                                    Query q = session.createQuery(sql);
2463    
2464                                    QueryPos qPos = QueryPos.getInstance(q);
2465    
2466                                    qPos.add(companyId);
2467    
2468                                    qPos.add(repositoryId);
2469    
2470                                    if (path != null) {
2471                                            qPos.add(path);
2472                                    }
2473    
2474                                    count = (Long)q.uniqueResult();
2475                            }
2476                            catch (Exception e) {
2477                                    throw processException(e);
2478                            }
2479                            finally {
2480                                    if (count == null) {
2481                                            count = Long.valueOf(0);
2482                                    }
2483    
2484                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P,
2485                                            finderArgs, count);
2486    
2487                                    closeSession(session);
2488                            }
2489                    }
2490    
2491                    return count.intValue();
2492            }
2493    
2494            /**
2495             * Returns the number of document library contents where companyId = &#63; and repositoryId = &#63; and path LIKE &#63;.
2496             *
2497             * @param companyId the company ID
2498             * @param repositoryId the repository ID
2499             * @param path the path
2500             * @return the number of matching document library contents
2501             * @throws SystemException if a system exception occurred
2502             */
2503            public int countByC_R_LikeP(long companyId, long repositoryId, String path)
2504                    throws SystemException {
2505                    Object[] finderArgs = new Object[] { companyId, repositoryId, path };
2506    
2507                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP,
2508                                    finderArgs, this);
2509    
2510                    if (count == null) {
2511                            StringBundler query = new StringBundler(4);
2512    
2513                            query.append(_SQL_COUNT_DLCONTENT_WHERE);
2514    
2515                            query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
2516    
2517                            query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
2518    
2519                            if (path == null) {
2520                                    query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
2521                            }
2522                            else {
2523                                    if (path.equals(StringPool.BLANK)) {
2524                                            query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
2525                                    }
2526                                    else {
2527                                            query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
2528                                    }
2529                            }
2530    
2531                            String sql = query.toString();
2532    
2533                            Session session = null;
2534    
2535                            try {
2536                                    session = openSession();
2537    
2538                                    Query q = session.createQuery(sql);
2539    
2540                                    QueryPos qPos = QueryPos.getInstance(q);
2541    
2542                                    qPos.add(companyId);
2543    
2544                                    qPos.add(repositoryId);
2545    
2546                                    if (path != null) {
2547                                            qPos.add(path);
2548                                    }
2549    
2550                                    count = (Long)q.uniqueResult();
2551                            }
2552                            catch (Exception e) {
2553                                    throw processException(e);
2554                            }
2555                            finally {
2556                                    if (count == null) {
2557                                            count = Long.valueOf(0);
2558                                    }
2559    
2560                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP,
2561                                            finderArgs, count);
2562    
2563                                    closeSession(session);
2564                            }
2565                    }
2566    
2567                    return count.intValue();
2568            }
2569    
2570            /**
2571             * Returns the number of document library contents where companyId = &#63; and repositoryId = &#63; and path = &#63; and version = &#63;.
2572             *
2573             * @param companyId the company ID
2574             * @param repositoryId the repository ID
2575             * @param path the path
2576             * @param version the version
2577             * @return the number of matching document library contents
2578             * @throws SystemException if a system exception occurred
2579             */
2580            public int countByC_R_P_V(long companyId, long repositoryId, String path,
2581                    String version) throws SystemException {
2582                    Object[] finderArgs = new Object[] {
2583                                    companyId, repositoryId, path, version
2584                            };
2585    
2586                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_R_P_V,
2587                                    finderArgs, this);
2588    
2589                    if (count == null) {
2590                            StringBundler query = new StringBundler(5);
2591    
2592                            query.append(_SQL_COUNT_DLCONTENT_WHERE);
2593    
2594                            query.append(_FINDER_COLUMN_C_R_P_V_COMPANYID_2);
2595    
2596                            query.append(_FINDER_COLUMN_C_R_P_V_REPOSITORYID_2);
2597    
2598                            if (path == null) {
2599                                    query.append(_FINDER_COLUMN_C_R_P_V_PATH_1);
2600                            }
2601                            else {
2602                                    if (path.equals(StringPool.BLANK)) {
2603                                            query.append(_FINDER_COLUMN_C_R_P_V_PATH_3);
2604                                    }
2605                                    else {
2606                                            query.append(_FINDER_COLUMN_C_R_P_V_PATH_2);
2607                                    }
2608                            }
2609    
2610                            if (version == null) {
2611                                    query.append(_FINDER_COLUMN_C_R_P_V_VERSION_1);
2612                            }
2613                            else {
2614                                    if (version.equals(StringPool.BLANK)) {
2615                                            query.append(_FINDER_COLUMN_C_R_P_V_VERSION_3);
2616                                    }
2617                                    else {
2618                                            query.append(_FINDER_COLUMN_C_R_P_V_VERSION_2);
2619                                    }
2620                            }
2621    
2622                            String sql = query.toString();
2623    
2624                            Session session = null;
2625    
2626                            try {
2627                                    session = openSession();
2628    
2629                                    Query q = session.createQuery(sql);
2630    
2631                                    QueryPos qPos = QueryPos.getInstance(q);
2632    
2633                                    qPos.add(companyId);
2634    
2635                                    qPos.add(repositoryId);
2636    
2637                                    if (path != null) {
2638                                            qPos.add(path);
2639                                    }
2640    
2641                                    if (version != null) {
2642                                            qPos.add(version);
2643                                    }
2644    
2645                                    count = (Long)q.uniqueResult();
2646                            }
2647                            catch (Exception e) {
2648                                    throw processException(e);
2649                            }
2650                            finally {
2651                                    if (count == null) {
2652                                            count = Long.valueOf(0);
2653                                    }
2654    
2655                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V,
2656                                            finderArgs, count);
2657    
2658                                    closeSession(session);
2659                            }
2660                    }
2661    
2662                    return count.intValue();
2663            }
2664    
2665            /**
2666             * Returns the number of document library contents.
2667             *
2668             * @return the number of document library contents
2669             * @throws SystemException if a system exception occurred
2670             */
2671            public int countAll() throws SystemException {
2672                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2673                                    FINDER_ARGS_EMPTY, this);
2674    
2675                    if (count == null) {
2676                            Session session = null;
2677    
2678                            try {
2679                                    session = openSession();
2680    
2681                                    Query q = session.createQuery(_SQL_COUNT_DLCONTENT);
2682    
2683                                    count = (Long)q.uniqueResult();
2684                            }
2685                            catch (Exception e) {
2686                                    throw processException(e);
2687                            }
2688                            finally {
2689                                    if (count == null) {
2690                                            count = Long.valueOf(0);
2691                                    }
2692    
2693                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2694                                            FINDER_ARGS_EMPTY, count);
2695    
2696                                    closeSession(session);
2697                            }
2698                    }
2699    
2700                    return count.intValue();
2701            }
2702    
2703            /**
2704             * Initializes the document library content persistence.
2705             */
2706            public void afterPropertiesSet() {
2707                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2708                                            com.liferay.portal.util.PropsUtil.get(
2709                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLContent")));
2710    
2711                    if (listenerClassNames.length > 0) {
2712                            try {
2713                                    List<ModelListener<DLContent>> listenersList = new ArrayList<ModelListener<DLContent>>();
2714    
2715                                    for (String listenerClassName : listenerClassNames) {
2716                                            Class<?> clazz = getClass();
2717    
2718                                            listenersList.add((ModelListener<DLContent>)InstanceFactory.newInstance(
2719                                                            clazz.getClassLoader(), listenerClassName));
2720                                    }
2721    
2722                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2723                            }
2724                            catch (Exception e) {
2725                                    _log.error(e);
2726                            }
2727                    }
2728            }
2729    
2730            public void destroy() {
2731                    EntityCacheUtil.removeCache(DLContentImpl.class.getName());
2732                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2733                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2734            }
2735    
2736            @BeanReference(type = DLContentPersistence.class)
2737            protected DLContentPersistence dlContentPersistence;
2738            @BeanReference(type = DLFileEntryPersistence.class)
2739            protected DLFileEntryPersistence dlFileEntryPersistence;
2740            @BeanReference(type = DLFileEntryMetadataPersistence.class)
2741            protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
2742            @BeanReference(type = DLFileEntryTypePersistence.class)
2743            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
2744            @BeanReference(type = DLFileRankPersistence.class)
2745            protected DLFileRankPersistence dlFileRankPersistence;
2746            @BeanReference(type = DLFileShortcutPersistence.class)
2747            protected DLFileShortcutPersistence dlFileShortcutPersistence;
2748            @BeanReference(type = DLFileVersionPersistence.class)
2749            protected DLFileVersionPersistence dlFileVersionPersistence;
2750            @BeanReference(type = DLFolderPersistence.class)
2751            protected DLFolderPersistence dlFolderPersistence;
2752            @BeanReference(type = DLSyncPersistence.class)
2753            protected DLSyncPersistence dlSyncPersistence;
2754            @BeanReference(type = ResourcePersistence.class)
2755            protected ResourcePersistence resourcePersistence;
2756            @BeanReference(type = UserPersistence.class)
2757            protected UserPersistence userPersistence;
2758            private static final String _SQL_SELECT_DLCONTENT = "SELECT dlContent FROM DLContent dlContent";
2759            private static final String _SQL_SELECT_DLCONTENT_WHERE = "SELECT dlContent FROM DLContent dlContent WHERE ";
2760            private static final String _SQL_COUNT_DLCONTENT = "SELECT COUNT(dlContent) FROM DLContent dlContent";
2761            private static final String _SQL_COUNT_DLCONTENT_WHERE = "SELECT COUNT(dlContent) FROM DLContent dlContent WHERE ";
2762            private static final String _FINDER_COLUMN_C_R_COMPANYID_2 = "dlContent.companyId = ? AND ";
2763            private static final String _FINDER_COLUMN_C_R_REPOSITORYID_2 = "dlContent.repositoryId = ?";
2764            private static final String _FINDER_COLUMN_C_R_P_COMPANYID_2 = "dlContent.companyId = ? AND ";
2765            private static final String _FINDER_COLUMN_C_R_P_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
2766            private static final String _FINDER_COLUMN_C_R_P_PATH_1 = "dlContent.path IS NULL";
2767            private static final String _FINDER_COLUMN_C_R_P_PATH_2 = "dlContent.path = ?";
2768            private static final String _FINDER_COLUMN_C_R_P_PATH_3 = "(dlContent.path IS NULL OR dlContent.path = ?)";
2769            private static final String _FINDER_COLUMN_C_R_LIKEP_COMPANYID_2 = "dlContent.companyId = ? AND ";
2770            private static final String _FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
2771            private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_1 = "dlContent.path LIKE NULL";
2772            private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_2 = "dlContent.path LIKE ?";
2773            private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_3 = "(dlContent.path IS NULL OR dlContent.path LIKE ?)";
2774            private static final String _FINDER_COLUMN_C_R_P_V_COMPANYID_2 = "dlContent.companyId = ? AND ";
2775            private static final String _FINDER_COLUMN_C_R_P_V_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
2776            private static final String _FINDER_COLUMN_C_R_P_V_PATH_1 = "dlContent.path IS NULL AND ";
2777            private static final String _FINDER_COLUMN_C_R_P_V_PATH_2 = "dlContent.path = ? AND ";
2778            private static final String _FINDER_COLUMN_C_R_P_V_PATH_3 = "(dlContent.path IS NULL OR dlContent.path = ?) AND ";
2779            private static final String _FINDER_COLUMN_C_R_P_V_VERSION_1 = "dlContent.version IS NULL";
2780            private static final String _FINDER_COLUMN_C_R_P_V_VERSION_2 = "dlContent.version = ?";
2781            private static final String _FINDER_COLUMN_C_R_P_V_VERSION_3 = "(dlContent.version IS NULL OR dlContent.version = ?)";
2782            private static final String _ORDER_BY_ENTITY_ALIAS = "dlContent.";
2783            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLContent exists with the primary key ";
2784            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLContent exists with the key {";
2785            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2786            private static Log _log = LogFactoryUtil.getLog(DLContentPersistenceImpl.class);
2787            private static DLContent _nullDLContent = new DLContentImpl() {
2788                            @Override
2789                            public Object clone() {
2790                                    return this;
2791                            }
2792    
2793                            @Override
2794                            public CacheModel<DLContent> toCacheModel() {
2795                                    return _nullDLContentCacheModel;
2796                            }
2797                    };
2798    
2799            private static CacheModel<DLContent> _nullDLContentCacheModel = new CacheModel<DLContent>() {
2800                            public DLContent toEntityModel() {
2801                                    return _nullDLContent;
2802                            }
2803                    };
2804    }