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