001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchOrgGroupRoleException;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.model.CacheModel;
033    import com.liferay.portal.model.MVCCModel;
034    import com.liferay.portal.model.OrgGroupRole;
035    import com.liferay.portal.model.impl.OrgGroupRoleImpl;
036    import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
037    import com.liferay.portal.service.persistence.OrgGroupRolePK;
038    import com.liferay.portal.service.persistence.OrgGroupRolePersistence;
039    
040    import java.io.Serializable;
041    
042    import java.util.Collections;
043    import java.util.HashMap;
044    import java.util.List;
045    import java.util.Map;
046    import java.util.Set;
047    
048    /**
049     * The persistence implementation for the org group role service.
050     *
051     * <p>
052     * Caching information and settings can be found in <code>portal.properties</code>
053     * </p>
054     *
055     * @author Brian Wing Shun Chan
056     * @see OrgGroupRolePersistence
057     * @see com.liferay.portal.service.persistence.OrgGroupRoleUtil
058     * @generated
059     */
060    @ProviderType
061    public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
062            implements OrgGroupRolePersistence {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. Always use {@link OrgGroupRoleUtil} to access the org group role persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
067             */
068            public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List1";
071            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List2";
073            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
074                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
075                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
077                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
080                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
083                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
085                            new String[] {
086                                    Long.class.getName(),
087                                    
088                            Integer.class.getName(), Integer.class.getName(),
089                                    OrderByComparator.class.getName()
090                            });
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
092                    new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
093                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
095                            new String[] { Long.class.getName() },
096                            OrgGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
097            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
098                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
100                            new String[] { Long.class.getName() });
101    
102            /**
103             * Returns all the org group roles where groupId = &#63;.
104             *
105             * @param groupId the group ID
106             * @return the matching org group roles
107             */
108            @Override
109            public List<OrgGroupRole> findByGroupId(long groupId) {
110                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
111            }
112    
113            /**
114             * Returns a range of all the org group roles where groupId = &#63;.
115             *
116             * <p>
117             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrgGroupRoleModelImpl}. 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.
118             * </p>
119             *
120             * @param groupId the group ID
121             * @param start the lower bound of the range of org group roles
122             * @param end the upper bound of the range of org group roles (not inclusive)
123             * @return the range of matching org group roles
124             */
125            @Override
126            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end) {
127                    return findByGroupId(groupId, start, end, null);
128            }
129    
130            /**
131             * Returns an ordered range of all the org group roles where groupId = &#63;.
132             *
133             * <p>
134             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrgGroupRoleModelImpl}. 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.
135             * </p>
136             *
137             * @param groupId the group ID
138             * @param start the lower bound of the range of org group roles
139             * @param end the upper bound of the range of org group roles (not inclusive)
140             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
141             * @return the ordered range of matching org group roles
142             */
143            @Override
144            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
145                    OrderByComparator<OrgGroupRole> orderByComparator) {
146                    boolean pagination = true;
147                    FinderPath finderPath = null;
148                    Object[] finderArgs = null;
149    
150                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
151                                    (orderByComparator == null)) {
152                            pagination = false;
153                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
154                            finderArgs = new Object[] { groupId };
155                    }
156                    else {
157                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
158                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
159                    }
160    
161                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
162                                    finderArgs, this);
163    
164                    if ((list != null) && !list.isEmpty()) {
165                            for (OrgGroupRole orgGroupRole : list) {
166                                    if ((groupId != orgGroupRole.getGroupId())) {
167                                            list = null;
168    
169                                            break;
170                                    }
171                            }
172                    }
173    
174                    if (list == null) {
175                            StringBundler query = null;
176    
177                            if (orderByComparator != null) {
178                                    query = new StringBundler(3 +
179                                                    (orderByComparator.getOrderByFields().length * 3));
180                            }
181                            else {
182                                    query = new StringBundler(3);
183                            }
184    
185                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
186    
187                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
188    
189                            if (orderByComparator != null) {
190                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
191                                            orderByComparator);
192                            }
193                            else
194                             if (pagination) {
195                                    query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
196                            }
197    
198                            String sql = query.toString();
199    
200                            Session session = null;
201    
202                            try {
203                                    session = openSession();
204    
205                                    Query q = session.createQuery(sql);
206    
207                                    QueryPos qPos = QueryPos.getInstance(q);
208    
209                                    qPos.add(groupId);
210    
211                                    if (!pagination) {
212                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
213                                                            start, end, false);
214    
215                                            Collections.sort(list);
216    
217                                            list = Collections.unmodifiableList(list);
218                                    }
219                                    else {
220                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
221                                                            start, end);
222                                    }
223    
224                                    cacheResult(list);
225    
226                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
227                            }
228                            catch (Exception e) {
229                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
230    
231                                    throw processException(e);
232                            }
233                            finally {
234                                    closeSession(session);
235                            }
236                    }
237    
238                    return list;
239            }
240    
241            /**
242             * Returns the first org group role in the ordered set where groupId = &#63;.
243             *
244             * @param groupId the group ID
245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
246             * @return the first matching org group role
247             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
248             */
249            @Override
250            public OrgGroupRole findByGroupId_First(long groupId,
251                    OrderByComparator<OrgGroupRole> orderByComparator)
252                    throws NoSuchOrgGroupRoleException {
253                    OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
254                                    orderByComparator);
255    
256                    if (orgGroupRole != null) {
257                            return orgGroupRole;
258                    }
259    
260                    StringBundler msg = new StringBundler(4);
261    
262                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
263    
264                    msg.append("groupId=");
265                    msg.append(groupId);
266    
267                    msg.append(StringPool.CLOSE_CURLY_BRACE);
268    
269                    throw new NoSuchOrgGroupRoleException(msg.toString());
270            }
271    
272            /**
273             * Returns the first org group role in the ordered set where groupId = &#63;.
274             *
275             * @param groupId the group ID
276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
277             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
278             */
279            @Override
280            public OrgGroupRole fetchByGroupId_First(long groupId,
281                    OrderByComparator<OrgGroupRole> orderByComparator) {
282                    List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
283    
284                    if (!list.isEmpty()) {
285                            return list.get(0);
286                    }
287    
288                    return null;
289            }
290    
291            /**
292             * Returns the last org group role in the ordered set where groupId = &#63;.
293             *
294             * @param groupId the group ID
295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
296             * @return the last matching org group role
297             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
298             */
299            @Override
300            public OrgGroupRole findByGroupId_Last(long groupId,
301                    OrderByComparator<OrgGroupRole> orderByComparator)
302                    throws NoSuchOrgGroupRoleException {
303                    OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
304                                    orderByComparator);
305    
306                    if (orgGroupRole != null) {
307                            return orgGroupRole;
308                    }
309    
310                    StringBundler msg = new StringBundler(4);
311    
312                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
313    
314                    msg.append("groupId=");
315                    msg.append(groupId);
316    
317                    msg.append(StringPool.CLOSE_CURLY_BRACE);
318    
319                    throw new NoSuchOrgGroupRoleException(msg.toString());
320            }
321    
322            /**
323             * Returns the last org group role in the ordered set where groupId = &#63;.
324             *
325             * @param groupId the group ID
326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
327             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
328             */
329            @Override
330            public OrgGroupRole fetchByGroupId_Last(long groupId,
331                    OrderByComparator<OrgGroupRole> orderByComparator) {
332                    int count = countByGroupId(groupId);
333    
334                    if (count == 0) {
335                            return null;
336                    }
337    
338                    List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
339                                    orderByComparator);
340    
341                    if (!list.isEmpty()) {
342                            return list.get(0);
343                    }
344    
345                    return null;
346            }
347    
348            /**
349             * Returns the org group roles before and after the current org group role in the ordered set where groupId = &#63;.
350             *
351             * @param orgGroupRolePK the primary key of the current org group role
352             * @param groupId the group ID
353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
354             * @return the previous, current, and next org group role
355             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
356             */
357            @Override
358            public OrgGroupRole[] findByGroupId_PrevAndNext(
359                    OrgGroupRolePK orgGroupRolePK, long groupId,
360                    OrderByComparator<OrgGroupRole> orderByComparator)
361                    throws NoSuchOrgGroupRoleException {
362                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
363    
364                    Session session = null;
365    
366                    try {
367                            session = openSession();
368    
369                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
370    
371                            array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
372                                            orderByComparator, true);
373    
374                            array[1] = orgGroupRole;
375    
376                            array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
377                                            orderByComparator, false);
378    
379                            return array;
380                    }
381                    catch (Exception e) {
382                            throw processException(e);
383                    }
384                    finally {
385                            closeSession(session);
386                    }
387            }
388    
389            protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
390                    OrgGroupRole orgGroupRole, long groupId,
391                    OrderByComparator<OrgGroupRole> orderByComparator, boolean previous) {
392                    StringBundler query = null;
393    
394                    if (orderByComparator != null) {
395                            query = new StringBundler(6 +
396                                            (orderByComparator.getOrderByFields().length * 6));
397                    }
398                    else {
399                            query = new StringBundler(3);
400                    }
401    
402                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
403    
404                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
405    
406                    if (orderByComparator != null) {
407                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
408    
409                            if (orderByConditionFields.length > 0) {
410                                    query.append(WHERE_AND);
411                            }
412    
413                            for (int i = 0; i < orderByConditionFields.length; i++) {
414                                    query.append(_ORDER_BY_ENTITY_ALIAS);
415                                    query.append(orderByConditionFields[i]);
416    
417                                    if ((i + 1) < orderByConditionFields.length) {
418                                            if (orderByComparator.isAscending() ^ previous) {
419                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
420                                            }
421                                            else {
422                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
423                                            }
424                                    }
425                                    else {
426                                            if (orderByComparator.isAscending() ^ previous) {
427                                                    query.append(WHERE_GREATER_THAN);
428                                            }
429                                            else {
430                                                    query.append(WHERE_LESSER_THAN);
431                                            }
432                                    }
433                            }
434    
435                            query.append(ORDER_BY_CLAUSE);
436    
437                            String[] orderByFields = orderByComparator.getOrderByFields();
438    
439                            for (int i = 0; i < orderByFields.length; i++) {
440                                    query.append(_ORDER_BY_ENTITY_ALIAS);
441                                    query.append(orderByFields[i]);
442    
443                                    if ((i + 1) < orderByFields.length) {
444                                            if (orderByComparator.isAscending() ^ previous) {
445                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
446                                            }
447                                            else {
448                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
449                                            }
450                                    }
451                                    else {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(ORDER_BY_ASC);
454                                            }
455                                            else {
456                                                    query.append(ORDER_BY_DESC);
457                                            }
458                                    }
459                            }
460                    }
461                    else {
462                            query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
463                    }
464    
465                    String sql = query.toString();
466    
467                    Query q = session.createQuery(sql);
468    
469                    q.setFirstResult(0);
470                    q.setMaxResults(2);
471    
472                    QueryPos qPos = QueryPos.getInstance(q);
473    
474                    qPos.add(groupId);
475    
476                    if (orderByComparator != null) {
477                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
478    
479                            for (Object value : values) {
480                                    qPos.add(value);
481                            }
482                    }
483    
484                    List<OrgGroupRole> list = q.list();
485    
486                    if (list.size() == 2) {
487                            return list.get(1);
488                    }
489                    else {
490                            return null;
491                    }
492            }
493    
494            /**
495             * Removes all the org group roles where groupId = &#63; from the database.
496             *
497             * @param groupId the group ID
498             */
499            @Override
500            public void removeByGroupId(long groupId) {
501                    for (OrgGroupRole orgGroupRole : findByGroupId(groupId,
502                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
503                            remove(orgGroupRole);
504                    }
505            }
506    
507            /**
508             * Returns the number of org group roles where groupId = &#63;.
509             *
510             * @param groupId the group ID
511             * @return the number of matching org group roles
512             */
513            @Override
514            public int countByGroupId(long groupId) {
515                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
516    
517                    Object[] finderArgs = new Object[] { groupId };
518    
519                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
520                                    this);
521    
522                    if (count == null) {
523                            StringBundler query = new StringBundler(2);
524    
525                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
526    
527                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
528    
529                            String sql = query.toString();
530    
531                            Session session = null;
532    
533                            try {
534                                    session = openSession();
535    
536                                    Query q = session.createQuery(sql);
537    
538                                    QueryPos qPos = QueryPos.getInstance(q);
539    
540                                    qPos.add(groupId);
541    
542                                    count = (Long)q.uniqueResult();
543    
544                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
545                            }
546                            catch (Exception e) {
547                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
548    
549                                    throw processException(e);
550                            }
551                            finally {
552                                    closeSession(session);
553                            }
554                    }
555    
556                    return count.intValue();
557            }
558    
559            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
560            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
561                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
562                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
563                            new String[] {
564                                    Long.class.getName(),
565                                    
566                            Integer.class.getName(), Integer.class.getName(),
567                                    OrderByComparator.class.getName()
568                            });
569            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
570                    new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
571                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
572                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
573                            new String[] { Long.class.getName() },
574                            OrgGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
575            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
576                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
577                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
578                            new String[] { Long.class.getName() });
579    
580            /**
581             * Returns all the org group roles where roleId = &#63;.
582             *
583             * @param roleId the role ID
584             * @return the matching org group roles
585             */
586            @Override
587            public List<OrgGroupRole> findByRoleId(long roleId) {
588                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
589            }
590    
591            /**
592             * Returns a range of all the org group roles where roleId = &#63;.
593             *
594             * <p>
595             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrgGroupRoleModelImpl}. 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.
596             * </p>
597             *
598             * @param roleId the role ID
599             * @param start the lower bound of the range of org group roles
600             * @param end the upper bound of the range of org group roles (not inclusive)
601             * @return the range of matching org group roles
602             */
603            @Override
604            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end) {
605                    return findByRoleId(roleId, start, end, null);
606            }
607    
608            /**
609             * Returns an ordered range of all the org group roles where roleId = &#63;.
610             *
611             * <p>
612             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrgGroupRoleModelImpl}. 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.
613             * </p>
614             *
615             * @param roleId the role ID
616             * @param start the lower bound of the range of org group roles
617             * @param end the upper bound of the range of org group roles (not inclusive)
618             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
619             * @return the ordered range of matching org group roles
620             */
621            @Override
622            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
623                    OrderByComparator<OrgGroupRole> orderByComparator) {
624                    boolean pagination = true;
625                    FinderPath finderPath = null;
626                    Object[] finderArgs = null;
627    
628                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
629                                    (orderByComparator == null)) {
630                            pagination = false;
631                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
632                            finderArgs = new Object[] { roleId };
633                    }
634                    else {
635                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
636                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
637                    }
638    
639                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
640                                    finderArgs, this);
641    
642                    if ((list != null) && !list.isEmpty()) {
643                            for (OrgGroupRole orgGroupRole : list) {
644                                    if ((roleId != orgGroupRole.getRoleId())) {
645                                            list = null;
646    
647                                            break;
648                                    }
649                            }
650                    }
651    
652                    if (list == null) {
653                            StringBundler query = null;
654    
655                            if (orderByComparator != null) {
656                                    query = new StringBundler(3 +
657                                                    (orderByComparator.getOrderByFields().length * 3));
658                            }
659                            else {
660                                    query = new StringBundler(3);
661                            }
662    
663                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
664    
665                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
666    
667                            if (orderByComparator != null) {
668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
669                                            orderByComparator);
670                            }
671                            else
672                             if (pagination) {
673                                    query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
674                            }
675    
676                            String sql = query.toString();
677    
678                            Session session = null;
679    
680                            try {
681                                    session = openSession();
682    
683                                    Query q = session.createQuery(sql);
684    
685                                    QueryPos qPos = QueryPos.getInstance(q);
686    
687                                    qPos.add(roleId);
688    
689                                    if (!pagination) {
690                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
691                                                            start, end, false);
692    
693                                            Collections.sort(list);
694    
695                                            list = Collections.unmodifiableList(list);
696                                    }
697                                    else {
698                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
699                                                            start, end);
700                                    }
701    
702                                    cacheResult(list);
703    
704                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
705                            }
706                            catch (Exception e) {
707                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
708    
709                                    throw processException(e);
710                            }
711                            finally {
712                                    closeSession(session);
713                            }
714                    }
715    
716                    return list;
717            }
718    
719            /**
720             * Returns the first org group role in the ordered set where roleId = &#63;.
721             *
722             * @param roleId the role ID
723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
724             * @return the first matching org group role
725             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
726             */
727            @Override
728            public OrgGroupRole findByRoleId_First(long roleId,
729                    OrderByComparator<OrgGroupRole> orderByComparator)
730                    throws NoSuchOrgGroupRoleException {
731                    OrgGroupRole orgGroupRole = fetchByRoleId_First(roleId,
732                                    orderByComparator);
733    
734                    if (orgGroupRole != null) {
735                            return orgGroupRole;
736                    }
737    
738                    StringBundler msg = new StringBundler(4);
739    
740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
741    
742                    msg.append("roleId=");
743                    msg.append(roleId);
744    
745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
746    
747                    throw new NoSuchOrgGroupRoleException(msg.toString());
748            }
749    
750            /**
751             * Returns the first org group role in the ordered set where roleId = &#63;.
752             *
753             * @param roleId the role ID
754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
755             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
756             */
757            @Override
758            public OrgGroupRole fetchByRoleId_First(long roleId,
759                    OrderByComparator<OrgGroupRole> orderByComparator) {
760                    List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
761    
762                    if (!list.isEmpty()) {
763                            return list.get(0);
764                    }
765    
766                    return null;
767            }
768    
769            /**
770             * Returns the last org group role in the ordered set where roleId = &#63;.
771             *
772             * @param roleId the role ID
773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
774             * @return the last matching org group role
775             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
776             */
777            @Override
778            public OrgGroupRole findByRoleId_Last(long roleId,
779                    OrderByComparator<OrgGroupRole> orderByComparator)
780                    throws NoSuchOrgGroupRoleException {
781                    OrgGroupRole orgGroupRole = fetchByRoleId_Last(roleId, orderByComparator);
782    
783                    if (orgGroupRole != null) {
784                            return orgGroupRole;
785                    }
786    
787                    StringBundler msg = new StringBundler(4);
788    
789                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
790    
791                    msg.append("roleId=");
792                    msg.append(roleId);
793    
794                    msg.append(StringPool.CLOSE_CURLY_BRACE);
795    
796                    throw new NoSuchOrgGroupRoleException(msg.toString());
797            }
798    
799            /**
800             * Returns the last org group role in the ordered set where roleId = &#63;.
801             *
802             * @param roleId the role ID
803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
804             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
805             */
806            @Override
807            public OrgGroupRole fetchByRoleId_Last(long roleId,
808                    OrderByComparator<OrgGroupRole> orderByComparator) {
809                    int count = countByRoleId(roleId);
810    
811                    if (count == 0) {
812                            return null;
813                    }
814    
815                    List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
816                                    orderByComparator);
817    
818                    if (!list.isEmpty()) {
819                            return list.get(0);
820                    }
821    
822                    return null;
823            }
824    
825            /**
826             * Returns the org group roles before and after the current org group role in the ordered set where roleId = &#63;.
827             *
828             * @param orgGroupRolePK the primary key of the current org group role
829             * @param roleId the role ID
830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
831             * @return the previous, current, and next org group role
832             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
833             */
834            @Override
835            public OrgGroupRole[] findByRoleId_PrevAndNext(
836                    OrgGroupRolePK orgGroupRolePK, long roleId,
837                    OrderByComparator<OrgGroupRole> orderByComparator)
838                    throws NoSuchOrgGroupRoleException {
839                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
840    
841                    Session session = null;
842    
843                    try {
844                            session = openSession();
845    
846                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
847    
848                            array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
849                                            orderByComparator, true);
850    
851                            array[1] = orgGroupRole;
852    
853                            array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
854                                            orderByComparator, false);
855    
856                            return array;
857                    }
858                    catch (Exception e) {
859                            throw processException(e);
860                    }
861                    finally {
862                            closeSession(session);
863                    }
864            }
865    
866            protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
867                    OrgGroupRole orgGroupRole, long roleId,
868                    OrderByComparator<OrgGroupRole> orderByComparator, boolean previous) {
869                    StringBundler query = null;
870    
871                    if (orderByComparator != null) {
872                            query = new StringBundler(6 +
873                                            (orderByComparator.getOrderByFields().length * 6));
874                    }
875                    else {
876                            query = new StringBundler(3);
877                    }
878    
879                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
880    
881                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
882    
883                    if (orderByComparator != null) {
884                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
885    
886                            if (orderByConditionFields.length > 0) {
887                                    query.append(WHERE_AND);
888                            }
889    
890                            for (int i = 0; i < orderByConditionFields.length; i++) {
891                                    query.append(_ORDER_BY_ENTITY_ALIAS);
892                                    query.append(orderByConditionFields[i]);
893    
894                                    if ((i + 1) < orderByConditionFields.length) {
895                                            if (orderByComparator.isAscending() ^ previous) {
896                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
897                                            }
898                                            else {
899                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
900                                            }
901                                    }
902                                    else {
903                                            if (orderByComparator.isAscending() ^ previous) {
904                                                    query.append(WHERE_GREATER_THAN);
905                                            }
906                                            else {
907                                                    query.append(WHERE_LESSER_THAN);
908                                            }
909                                    }
910                            }
911    
912                            query.append(ORDER_BY_CLAUSE);
913    
914                            String[] orderByFields = orderByComparator.getOrderByFields();
915    
916                            for (int i = 0; i < orderByFields.length; i++) {
917                                    query.append(_ORDER_BY_ENTITY_ALIAS);
918                                    query.append(orderByFields[i]);
919    
920                                    if ((i + 1) < orderByFields.length) {
921                                            if (orderByComparator.isAscending() ^ previous) {
922                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
923                                            }
924                                            else {
925                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
926                                            }
927                                    }
928                                    else {
929                                            if (orderByComparator.isAscending() ^ previous) {
930                                                    query.append(ORDER_BY_ASC);
931                                            }
932                                            else {
933                                                    query.append(ORDER_BY_DESC);
934                                            }
935                                    }
936                            }
937                    }
938                    else {
939                            query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
940                    }
941    
942                    String sql = query.toString();
943    
944                    Query q = session.createQuery(sql);
945    
946                    q.setFirstResult(0);
947                    q.setMaxResults(2);
948    
949                    QueryPos qPos = QueryPos.getInstance(q);
950    
951                    qPos.add(roleId);
952    
953                    if (orderByComparator != null) {
954                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
955    
956                            for (Object value : values) {
957                                    qPos.add(value);
958                            }
959                    }
960    
961                    List<OrgGroupRole> list = q.list();
962    
963                    if (list.size() == 2) {
964                            return list.get(1);
965                    }
966                    else {
967                            return null;
968                    }
969            }
970    
971            /**
972             * Removes all the org group roles where roleId = &#63; from the database.
973             *
974             * @param roleId the role ID
975             */
976            @Override
977            public void removeByRoleId(long roleId) {
978                    for (OrgGroupRole orgGroupRole : findByRoleId(roleId,
979                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
980                            remove(orgGroupRole);
981                    }
982            }
983    
984            /**
985             * Returns the number of org group roles where roleId = &#63;.
986             *
987             * @param roleId the role ID
988             * @return the number of matching org group roles
989             */
990            @Override
991            public int countByRoleId(long roleId) {
992                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
993    
994                    Object[] finderArgs = new Object[] { roleId };
995    
996                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
997                                    this);
998    
999                    if (count == null) {
1000                            StringBundler query = new StringBundler(2);
1001    
1002                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1003    
1004                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1005    
1006                            String sql = query.toString();
1007    
1008                            Session session = null;
1009    
1010                            try {
1011                                    session = openSession();
1012    
1013                                    Query q = session.createQuery(sql);
1014    
1015                                    QueryPos qPos = QueryPos.getInstance(q);
1016    
1017                                    qPos.add(roleId);
1018    
1019                                    count = (Long)q.uniqueResult();
1020    
1021                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1022                            }
1023                            catch (Exception e) {
1024                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1025    
1026                                    throw processException(e);
1027                            }
1028                            finally {
1029                                    closeSession(session);
1030                            }
1031                    }
1032    
1033                    return count.intValue();
1034            }
1035    
1036            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1037    
1038            public OrgGroupRolePersistenceImpl() {
1039                    setModelClass(OrgGroupRole.class);
1040            }
1041    
1042            /**
1043             * Caches the org group role in the entity cache if it is enabled.
1044             *
1045             * @param orgGroupRole the org group role
1046             */
1047            @Override
1048            public void cacheResult(OrgGroupRole orgGroupRole) {
1049                    EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1050                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1051    
1052                    orgGroupRole.resetOriginalValues();
1053            }
1054    
1055            /**
1056             * Caches the org group roles in the entity cache if it is enabled.
1057             *
1058             * @param orgGroupRoles the org group roles
1059             */
1060            @Override
1061            public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
1062                    for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1063                            if (EntityCacheUtil.getResult(
1064                                                    OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1065                                                    OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey()) == null) {
1066                                    cacheResult(orgGroupRole);
1067                            }
1068                            else {
1069                                    orgGroupRole.resetOriginalValues();
1070                            }
1071                    }
1072            }
1073    
1074            /**
1075             * Clears the cache for all org group roles.
1076             *
1077             * <p>
1078             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1079             * </p>
1080             */
1081            @Override
1082            public void clearCache() {
1083                    EntityCacheUtil.clearCache(OrgGroupRoleImpl.class);
1084    
1085                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1086                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1087                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1088            }
1089    
1090            /**
1091             * Clears the cache for the org group role.
1092             *
1093             * <p>
1094             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1095             * </p>
1096             */
1097            @Override
1098            public void clearCache(OrgGroupRole orgGroupRole) {
1099                    EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1100                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1101    
1102                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1103                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1104            }
1105    
1106            @Override
1107            public void clearCache(List<OrgGroupRole> orgGroupRoles) {
1108                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1109                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1110    
1111                    for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1112                            EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1113                                    OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1114                    }
1115            }
1116    
1117            /**
1118             * Creates a new org group role with the primary key. Does not add the org group role to the database.
1119             *
1120             * @param orgGroupRolePK the primary key for the new org group role
1121             * @return the new org group role
1122             */
1123            @Override
1124            public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
1125                    OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
1126    
1127                    orgGroupRole.setNew(true);
1128                    orgGroupRole.setPrimaryKey(orgGroupRolePK);
1129    
1130                    return orgGroupRole;
1131            }
1132    
1133            /**
1134             * Removes the org group role with the primary key from the database. Also notifies the appropriate model listeners.
1135             *
1136             * @param orgGroupRolePK the primary key of the org group role
1137             * @return the org group role that was removed
1138             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1139             */
1140            @Override
1141            public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
1142                    throws NoSuchOrgGroupRoleException {
1143                    return remove((Serializable)orgGroupRolePK);
1144            }
1145    
1146            /**
1147             * Removes the org group role with the primary key from the database. Also notifies the appropriate model listeners.
1148             *
1149             * @param primaryKey the primary key of the org group role
1150             * @return the org group role that was removed
1151             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1152             */
1153            @Override
1154            public OrgGroupRole remove(Serializable primaryKey)
1155                    throws NoSuchOrgGroupRoleException {
1156                    Session session = null;
1157    
1158                    try {
1159                            session = openSession();
1160    
1161                            OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1162                                            primaryKey);
1163    
1164                            if (orgGroupRole == null) {
1165                                    if (_log.isWarnEnabled()) {
1166                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1167                                    }
1168    
1169                                    throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1170                                            primaryKey);
1171                            }
1172    
1173                            return remove(orgGroupRole);
1174                    }
1175                    catch (NoSuchOrgGroupRoleException nsee) {
1176                            throw nsee;
1177                    }
1178                    catch (Exception e) {
1179                            throw processException(e);
1180                    }
1181                    finally {
1182                            closeSession(session);
1183                    }
1184            }
1185    
1186            @Override
1187            protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole) {
1188                    orgGroupRole = toUnwrappedModel(orgGroupRole);
1189    
1190                    Session session = null;
1191    
1192                    try {
1193                            session = openSession();
1194    
1195                            if (!session.contains(orgGroupRole)) {
1196                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1197                                                    orgGroupRole.getPrimaryKeyObj());
1198                            }
1199    
1200                            if (orgGroupRole != null) {
1201                                    session.delete(orgGroupRole);
1202                            }
1203                    }
1204                    catch (Exception e) {
1205                            throw processException(e);
1206                    }
1207                    finally {
1208                            closeSession(session);
1209                    }
1210    
1211                    if (orgGroupRole != null) {
1212                            clearCache(orgGroupRole);
1213                    }
1214    
1215                    return orgGroupRole;
1216            }
1217    
1218            @Override
1219            public OrgGroupRole updateImpl(OrgGroupRole orgGroupRole) {
1220                    orgGroupRole = toUnwrappedModel(orgGroupRole);
1221    
1222                    boolean isNew = orgGroupRole.isNew();
1223    
1224                    OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
1225    
1226                    Session session = null;
1227    
1228                    try {
1229                            session = openSession();
1230    
1231                            if (orgGroupRole.isNew()) {
1232                                    session.save(orgGroupRole);
1233    
1234                                    orgGroupRole.setNew(false);
1235                            }
1236                            else {
1237                                    session.merge(orgGroupRole);
1238                            }
1239                    }
1240                    catch (Exception e) {
1241                            throw processException(e);
1242                    }
1243                    finally {
1244                            closeSession(session);
1245                    }
1246    
1247                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1248    
1249                    if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
1250                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1251                    }
1252    
1253                    else {
1254                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
1255                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1256                                    Object[] args = new Object[] {
1257                                                    orgGroupRoleModelImpl.getOriginalGroupId()
1258                                            };
1259    
1260                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1261                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1262                                            args);
1263    
1264                                    args = new Object[] { orgGroupRoleModelImpl.getGroupId() };
1265    
1266                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1267                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1268                                            args);
1269                            }
1270    
1271                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
1272                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1273                                    Object[] args = new Object[] {
1274                                                    orgGroupRoleModelImpl.getOriginalRoleId()
1275                                            };
1276    
1277                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1279                                            args);
1280    
1281                                    args = new Object[] { orgGroupRoleModelImpl.getRoleId() };
1282    
1283                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1284                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1285                                            args);
1286                            }
1287                    }
1288    
1289                    EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1290                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole,
1291                            false);
1292    
1293                    orgGroupRole.resetOriginalValues();
1294    
1295                    return orgGroupRole;
1296            }
1297    
1298            protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
1299                    if (orgGroupRole instanceof OrgGroupRoleImpl) {
1300                            return orgGroupRole;
1301                    }
1302    
1303                    OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
1304    
1305                    orgGroupRoleImpl.setNew(orgGroupRole.isNew());
1306                    orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
1307    
1308                    orgGroupRoleImpl.setMvccVersion(orgGroupRole.getMvccVersion());
1309                    orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
1310                    orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
1311                    orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
1312    
1313                    return orgGroupRoleImpl;
1314            }
1315    
1316            /**
1317             * Returns the org group role with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1318             *
1319             * @param primaryKey the primary key of the org group role
1320             * @return the org group role
1321             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1322             */
1323            @Override
1324            public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
1325                    throws NoSuchOrgGroupRoleException {
1326                    OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1327    
1328                    if (orgGroupRole == null) {
1329                            if (_log.isWarnEnabled()) {
1330                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1331                            }
1332    
1333                            throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1334                                    primaryKey);
1335                    }
1336    
1337                    return orgGroupRole;
1338            }
1339    
1340            /**
1341             * Returns the org group role with the primary key or throws a {@link NoSuchOrgGroupRoleException} if it could not be found.
1342             *
1343             * @param orgGroupRolePK the primary key of the org group role
1344             * @return the org group role
1345             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1346             */
1347            @Override
1348            public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1349                    throws NoSuchOrgGroupRoleException {
1350                    return findByPrimaryKey((Serializable)orgGroupRolePK);
1351            }
1352    
1353            /**
1354             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
1355             *
1356             * @param primaryKey the primary key of the org group role
1357             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
1358             */
1359            @Override
1360            public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey) {
1361                    OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1362                                    OrgGroupRoleImpl.class, primaryKey);
1363    
1364                    if (orgGroupRole == _nullOrgGroupRole) {
1365                            return null;
1366                    }
1367    
1368                    if (orgGroupRole == null) {
1369                            Session session = null;
1370    
1371                            try {
1372                                    session = openSession();
1373    
1374                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1375                                                    primaryKey);
1376    
1377                                    if (orgGroupRole != null) {
1378                                            cacheResult(orgGroupRole);
1379                                    }
1380                                    else {
1381                                            EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1382                                                    OrgGroupRoleImpl.class, primaryKey, _nullOrgGroupRole);
1383                                    }
1384                            }
1385                            catch (Exception e) {
1386                                    EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1387                                            OrgGroupRoleImpl.class, primaryKey);
1388    
1389                                    throw processException(e);
1390                            }
1391                            finally {
1392                                    closeSession(session);
1393                            }
1394                    }
1395    
1396                    return orgGroupRole;
1397            }
1398    
1399            /**
1400             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
1401             *
1402             * @param orgGroupRolePK the primary key of the org group role
1403             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
1404             */
1405            @Override
1406            public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK) {
1407                    return fetchByPrimaryKey((Serializable)orgGroupRolePK);
1408            }
1409    
1410            @Override
1411            public Map<Serializable, OrgGroupRole> fetchByPrimaryKeys(
1412                    Set<Serializable> primaryKeys) {
1413                    if (primaryKeys.isEmpty()) {
1414                            return Collections.emptyMap();
1415                    }
1416    
1417                    Map<Serializable, OrgGroupRole> map = new HashMap<Serializable, OrgGroupRole>();
1418    
1419                    for (Serializable primaryKey : primaryKeys) {
1420                            OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1421    
1422                            if (orgGroupRole != null) {
1423                                    map.put(primaryKey, orgGroupRole);
1424                            }
1425                    }
1426    
1427                    return map;
1428            }
1429    
1430            /**
1431             * Returns all the org group roles.
1432             *
1433             * @return the org group roles
1434             */
1435            @Override
1436            public List<OrgGroupRole> findAll() {
1437                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1438            }
1439    
1440            /**
1441             * Returns a range of all the org group roles.
1442             *
1443             * <p>
1444             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrgGroupRoleModelImpl}. 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.
1445             * </p>
1446             *
1447             * @param start the lower bound of the range of org group roles
1448             * @param end the upper bound of the range of org group roles (not inclusive)
1449             * @return the range of org group roles
1450             */
1451            @Override
1452            public List<OrgGroupRole> findAll(int start, int end) {
1453                    return findAll(start, end, null);
1454            }
1455    
1456            /**
1457             * Returns an ordered range of all the org group roles.
1458             *
1459             * <p>
1460             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link OrgGroupRoleModelImpl}. 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.
1461             * </p>
1462             *
1463             * @param start the lower bound of the range of org group roles
1464             * @param end the upper bound of the range of org group roles (not inclusive)
1465             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1466             * @return the ordered range of org group roles
1467             */
1468            @Override
1469            public List<OrgGroupRole> findAll(int start, int end,
1470                    OrderByComparator<OrgGroupRole> orderByComparator) {
1471                    boolean pagination = true;
1472                    FinderPath finderPath = null;
1473                    Object[] finderArgs = null;
1474    
1475                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1476                                    (orderByComparator == null)) {
1477                            pagination = false;
1478                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1479                            finderArgs = FINDER_ARGS_EMPTY;
1480                    }
1481                    else {
1482                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1483                            finderArgs = new Object[] { start, end, orderByComparator };
1484                    }
1485    
1486                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1487                                    finderArgs, this);
1488    
1489                    if (list == null) {
1490                            StringBundler query = null;
1491                            String sql = null;
1492    
1493                            if (orderByComparator != null) {
1494                                    query = new StringBundler(2 +
1495                                                    (orderByComparator.getOrderByFields().length * 3));
1496    
1497                                    query.append(_SQL_SELECT_ORGGROUPROLE);
1498    
1499                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1500                                            orderByComparator);
1501    
1502                                    sql = query.toString();
1503                            }
1504                            else {
1505                                    sql = _SQL_SELECT_ORGGROUPROLE;
1506    
1507                                    if (pagination) {
1508                                            sql = sql.concat(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
1509                                    }
1510                            }
1511    
1512                            Session session = null;
1513    
1514                            try {
1515                                    session = openSession();
1516    
1517                                    Query q = session.createQuery(sql);
1518    
1519                                    if (!pagination) {
1520                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1521                                                            start, end, false);
1522    
1523                                            Collections.sort(list);
1524    
1525                                            list = Collections.unmodifiableList(list);
1526                                    }
1527                                    else {
1528                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1529                                                            start, end);
1530                                    }
1531    
1532                                    cacheResult(list);
1533    
1534                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1535                            }
1536                            catch (Exception e) {
1537                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1538    
1539                                    throw processException(e);
1540                            }
1541                            finally {
1542                                    closeSession(session);
1543                            }
1544                    }
1545    
1546                    return list;
1547            }
1548    
1549            /**
1550             * Removes all the org group roles from the database.
1551             *
1552             */
1553            @Override
1554            public void removeAll() {
1555                    for (OrgGroupRole orgGroupRole : findAll()) {
1556                            remove(orgGroupRole);
1557                    }
1558            }
1559    
1560            /**
1561             * Returns the number of org group roles.
1562             *
1563             * @return the number of org group roles
1564             */
1565            @Override
1566            public int countAll() {
1567                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1568                                    FINDER_ARGS_EMPTY, this);
1569    
1570                    if (count == null) {
1571                            Session session = null;
1572    
1573                            try {
1574                                    session = openSession();
1575    
1576                                    Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1577    
1578                                    count = (Long)q.uniqueResult();
1579    
1580                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1581                                            FINDER_ARGS_EMPTY, count);
1582                            }
1583                            catch (Exception e) {
1584                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1585                                            FINDER_ARGS_EMPTY);
1586    
1587                                    throw processException(e);
1588                            }
1589                            finally {
1590                                    closeSession(session);
1591                            }
1592                    }
1593    
1594                    return count.intValue();
1595            }
1596    
1597            /**
1598             * Initializes the org group role persistence.
1599             */
1600            public void afterPropertiesSet() {
1601            }
1602    
1603            public void destroy() {
1604                    EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1605                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1606                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1607                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1608            }
1609    
1610            private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1611            private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1612            private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1613            private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1614            private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1615            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1616            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1617            private static final Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1618            private static final OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1619                            @Override
1620                            public Object clone() {
1621                                    return this;
1622                            }
1623    
1624                            @Override
1625                            public CacheModel<OrgGroupRole> toCacheModel() {
1626                                    return _nullOrgGroupRoleCacheModel;
1627                            }
1628                    };
1629    
1630            private static final CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new NullCacheModel();
1631    
1632            private static class NullCacheModel implements CacheModel<OrgGroupRole>,
1633                    MVCCModel {
1634                    @Override
1635                    public long getMvccVersion() {
1636                            return -1;
1637                    }
1638    
1639                    @Override
1640                    public void setMvccVersion(long mvccVersion) {
1641                    }
1642    
1643                    @Override
1644                    public OrgGroupRole toEntityModel() {
1645                            return _nullOrgGroupRole;
1646                    }
1647            }
1648    }