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