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