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