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