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