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