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