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