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