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