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