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