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