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