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