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