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