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