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