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