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