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