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