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