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