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